-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
mypy type checking doesn't seem to work #366
Comments
We should make the docs clearer, but while mypy won't give a false negative when it parses a pydantic model, it obviously can't check if model validation is going to pass or fail. Also as per #245 mypy can't check whether an attribute exists. This is a (completely understandable) limitation of mypy. You might want to use dataclasses which mypy should support better. |
Yes, please make the docs clearer. Essentially I can't use pydantic if I want static type checking. The docs say:
Well, I would claim that, no, mypy does not work correctly with pydantic. The docs are misleading. |
That's fair, I'll update docs. Some things do work however from pydantic import BaseModel
class Test(BaseModel):
test_int: int
test_str: str
m = Test(test_int=42, test_str='foobar')
print(123 + m.test_str) Returns:
While the same with So I would say mypy and pydantic work together partially, "Essentially I can't use pydantic if I want static type checking." is a bit too far the other way. |
see #372. |
* Test on other OSes, remove benchmarks * fix pytest-speed for 3.7 * remove windows xfail, revert pyproject changes * uprev pytest, pytest-pretty * add print to windows * more eprints * remove test-os py cache * remove extra prints * revert xfail * remove pytest-speed on codspeed ci * install ptyest-benchmark with codspeed * clear codspeed cache
Bug
For bugs/questions:
import sys; print(sys.version)
: 3.7import pydantic; print(pydantic.VERSION)
: masterWhere possible please include a self contained code snippet describing your
bug, question, or where applicable feature request:
The above is the example from the docs: https://pydantic-docs.helpmanual.io/#usage-with-mypy
With
mypy 0.650
, doesn't raise any validation error.Moreover, changing
print(m.age)
toprint(m.agexxx)
, it still doesn't give any error saying that the field name is wrong.The text was updated successfully, but these errors were encountered: