pydantic: `pydantic-mypy` plugin is incompatible with `pyproject.toml` config in `mypy>0.900`
Bug
Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:
pydantic version: 1.8.2
pydantic compiled: True
install path: /opt/venv/lib/python3.8/site-packages/pydantic
python version: 3.8.5 (default, Sep 10 2020, 16:58:22) [GCC 8.3.0]
platform: Linux-5.10.25-linuxkit-x86_64-with-glibc2.2.5
optional deps. installed: ['typing-extensions']
The newest release of mypy
(0.900-0.901) has introduced pyproject.toml
configuration in addition to the older mypy.ini
in accordance with PEP-518. However, the pydantic-mypy
plugin still expects an INI-formatted config file, such that TOML-configured mypy with the plugin enabled results in a parse error:
Error constructing plugin instance of PydanticPlugin
Traceback (most recent call last):
File "/opt/venv/bin/mypy", line 8, in <module>
sys.exit(console_entry())
File "/opt/venv/lib/python3.8/site-packages/mypy/__main__.py", line 11, in console_entry
main(None, sys.stdout, sys.stderr)
File "mypy/main.py", line 98, in main
File "mypy/build.py", line 179, in build
File "mypy/build.py", line 229, in _build
File "mypy/build.py", line 475, in load_plugins
File "mypy/build.py", line 453, in load_plugins_from_config
File "pydantic/mypy.py", line 77, in pydantic.mypy.PydanticPlugin.__init__
File "pydantic/mypy.py", line 114, in pydantic.mypy.PydanticPluginConfig.__init__
File "/usr/local/lib/python3.8/configparser.py", line 697, in read
self._read(fp, filename)
File "/usr/local/lib/python3.8/configparser.py", line 1113, in _read
raise e
configparser.ParsingError: Source contains parsing errors: 'pyproject.toml'
[line 12]: ']\n'
[line 17]: ']\n'
[line 65]: ']\n'
...
Note that the plugin still works in mypy>0.900
provided an INI configuration file is still provided. To bring the plugin up to speed for the newest mypy releases I believe we’ll need a TOML parser option in addition to the default ConfigParser
in the plugin constructor.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 36
- Comments: 21 (9 by maintainers)
Commits related to this issue
- Update dependencies mypy 0.9xx updates will be postponed until the pydantic plugin achieves compatibility (samuelcolvin/pydantic#2895). ```text .venv ❯ poetry update Updating dependencies Resolving ... — committed to br3ndonland/inboard by br3ndonland 3 years ago
- Move mypy configuration to .mypy.ini pydantic's mypy plugin doesn't yet work properly with pyproject.toml (https://github.com/samuelcolvin/pydantic/issues/2895, fixed but not yet released). — committed to jugmac00/lpcraft by cjwatson 3 years ago
- fix(api): mypy cfg missing pydantic plugin (#859) Realized we weren't setting up the pydantic mypy plugin. Oops. https://pydantic-docs.helpmanual.io/mypy_plugin/#configuring-the-plugin rel: https:/... — committed to recipeyak/recipeyak by sbdchd 2 years ago
Not making any promises, but I’ll try to get a new release out next week.
1.9.0 release has been published with
pyproject.toml
support 🎉Thanks, really excited to see this released.
@samuelcolvin Is there anything we can do to help you get a new release out? Would it be helpful if I made prep branch like this?
@Ierezell See #2908, which references this branch: https://github.com/jrwalk/pydantic/tree/toml-support
It also helps to thumb up the original comment in this issue so maintainers have a sense of the number of users this affects.
Reading the config will fail as soon as TOML-specific stuff is present in
pyproject.toml
. E.g. addingor similar should already be enough to break the
ConfigParser
.Should also update the user guide to show how to enable and configure the plugin for
pyproject.toml
. This will likely be what a vast majority of users will migrate to given how popular usingpyproject.toml
is becoming:https://pydantic-docs.helpmanual.io/mypy_plugin/#enabling-the-plugin https://pydantic-docs.helpmanual.io/mypy_plugin/#configuring-the-plugin
Hi, I stumbled across this issue as I was trying to use the new norms (pyproject.toml) and I’m building an API with FastApi.
Is there a branch or something I can help you testing with ?
Have a great day.
@johnthagen yep, I’ve got that in a PR I’m working on!
@Ierezell feel free to use the branch @johnthagen linked, that should resolve it. And ++ to the thumbs-up as well - that mypy release is super fresh as well, so it just wouldn’t have surfaced until very recently.
In the meantime, everything should work perfectly happily with
mypy>0.900
, just with the config inmypy.ini
rather thanpyproject.toml
- and converting the config options back and forth is straightforward (the PR has an example to be added to the pydantic docs).