-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Current best practices for combining pydantic
& mypy
#995
Comments
The solution is to use the mypy plugin with that mypy should work correctly. yes, #245 is outdated. |
@samuelcolvin having just installed
I'm getting |
Can confirm, installing |
I've just tried this myself and it works fine: > mkdir scratch
> cd scratch
> touch app.py
[copy python https://pydantic-docs.helpmanual.io/mypy_plugin/]
> touch setup.cfg
[copy the two lines from above]
> pip install -U pydantic mypy
...
> mypy app.py
app.py:16: error: "Model" has no attribute "middle_name"
app.py:17: error: Missing named argument "age" for "Model"
app.py:17: error: Missing named argument "list_of_ints" for "Model"
Found 3 errors in 1 file (checked 1 source file) |
mypy is not a dependency of pydantic, thus installing pydantic can't force mypy to update. |
I guess with the |
@DBCerigo As far as I understand, nothing has changed about pydantic's relationship with mypy. It was a development-only dependency before, and it still is. If you never import If you want to use the mypy plugin while type-checking your code using mypy, then yes, you'd need to have mypy installed 😄. But that was also the case before. |
@dmontagu appreciated, sounds completely right :) thanks for responding |
No, mypy is definitely not a dependency of pydantic because you can use
pydantic without mypy.
In theory mypy could become an optional dependency on pydantic, but without
reading the docs that wouldn't have helped you.
We could however add a note to the docs pointing out the minimum version of
mypy required to use plugins.
…On Thu, Nov 14, 2019, 08:41 Daniel Burkhardt Cerigo < ***@***.***> wrote:
I guess with the pydantic-mypy plugin introduced in 1.1, mypy is now a
dep of pydantic? 🤷♂️ It's not biggy to me :) just hopefully to try to
help make improvements.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#995>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA62GGMMWLIFSL6HHRXK36TQTUFLDANCNFSM4JM7ZONA>
.
|
I am still having this issue with mypy 0.782 and pydantic 1.6.1 |
Also having this issue with mypy 0.782 and pydantic 1.6.1 |
If your using the mypy plugin on VS Code you could be getting the error
|
Mypy works from command line, but fails with pre-commit:
Any ideas how to fix? |
I was able to solve issue using additional_dependencies - repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.800
hooks:
- id: mypy
additional_dependencies:
- 'pydantic' |
…ieldValidationInfo` (pydantic#995)
Part 1: there seems to be an inconsistency between the conclusion from this issue #245 being "Solution here is to use dataclasses which I think mypy should work with properly.", and then this pydantic docs page https://pydantic-docs.helpmanual.io/usage/mypy/
Is the conclusion of that issue now defunct, and inheriting from
BaseModel
is supposed to work correctly withmypy
, or are the docs incorrect? I raise this as in our current usage ofBaseModel
we get the ("mypy
not working") behaviour from #245 and not the ("mypy
working") behaviour from docs.Part 2: given we really like
pydantic
(a thanks and congrats to all contributors to it!), what is currently advised by corepydantic
devs as the best practice to usepydantic
while still get type-checking withmypy
. The options I found are:a. Use
pydantic.dataclasses
as per https://pydantic-docs.helpmanual.io/usage/dataclasses/#nested-dataclassesb. Use the
pydantic.mypy
plugin* as per https://pydantic-docs.helpmanual.io/mypy_plugin/The hope with this question is that it can provide advice to others out there looking to combine
mypy
&pydantic
on how best to do so currently 😸Other refs for
mypy
+pydantic
usage: #366 #957 #156 #238*Note, in this same docs page it states that
mypy
works withpydantic
(assuming implying withBaseModel
also) out of the box, which is again not what #245 concludes 😬(I personally think
mypy
is pretty 👎, so I appreciate the presumed headache it causes you all too, but that optional type-hinting in general is very 👍)The text was updated successfully, but these errors were encountered: