You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mypy is flagging code pasted directly from the Pydantic docs (involving initializing models with dictionary values for nested classes) as incorrectly typed.
Mypy should validate the above code without errors, as it is example code directly from Pydantic's docs.
Actual Behavior
test.py:26: error: Argument "pet" to "Model" has incompatible type "dict[str, object]"; expected "Cat | Dog | Lizard" [arg-type]
Found 1 error in 1 file (checked 1 source file
Your Environment
Mypy version used: 1.10.0
Mypy command-line flags: None
Mypy configuration options from mypy.ini (and other config files): mypy.ini
Python version used: 3.10.11
Pydantic version used: 2.7.1
The text was updated successfully, but these errors were encountered:
The Pydantic docs appear to treat code initializing nested classes using dictionaries containing the fields and values as correct (and the code does work for me if I run it), but Mypy is flagging such code as incorrect.
Bug Report
Mypy is flagging code pasted directly from the Pydantic docs (involving initializing models with dictionary values for nested classes) as incorrectly typed.
To Reproduce
Save the following code (directly from the current Pydantic docs to a Python file.
Then run mypy on it.
Expected Behavior
Mypy should validate the above code without errors, as it is example code directly from Pydantic's docs.
Actual Behavior
Your Environment
mypy.ini
(and other config files): mypy.iniThe text was updated successfully, but these errors were encountered: