-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 error on default_factory=list in pydantic 1.10 #4457
Comments
Same with dict. parameters: Dict[str, str] = Field(default_factory=dict) error: Incompatible types in assignment (expression has type "Dict[_KT, _VT]", variable has type "Dict[str, str]") |
Could be related to #4086, @richardxia any idea how this can be fixed? By the way, @tapple @Pentusha it would be much easier for you and me if problems like this got caught before releasing v1.10. In future, please consider testing pydantic pre-releases. We had three pre-releases over 2 weeks and i talked about them a lot on twitter. |
I don't think it's related to #4086; that PR should have only affected whether the mypy plugin thinks a given field is required or not. I also tested reverting that commit locally and testing the example code in this ticket, but I still see the same error message show up. I did a git bisect, and it looks like 460f858 (#3430) is the first commit that fails to type check the example code in this ticket. Maybe @klaa97 could take a look? |
@richardxia Thank you for the tag and sorry for this 🤦 I am pretty sure this comes from my commit, here in particular: https://github.com/klaa97/pydantic/blob/13e0a25cc8c3c8ec5a264f6c9635350ea6b71f3e/pydantic/mypy.py#L165 . In particular, it comes from the I wish we'd find it sooner :(, but I'm afraid I cannot find much more documentation on how to tackle this error therefore I'd say reverting the change might be the easiest fix. |
Thanks so much for looking into this. Maybe we could comment out that check for now and ask on the mypy repo if there's a work around? |
I completely agree, it looks like a plan! I could open a PR by end of the day to remove the check on |
Please tag me in the mypy discussion, I'd be interested to see what they say. |
Initial Checks
Description
mypy complains about default_factory = list in pydantic 1.10
But using [] works fine. I think this inconsistency should be fixed
Also, I don't think the documentation indicates that pydantic deep-copies mutable default values. I found that out at https://stackoverflow.com/questions/63793662/how-to-give-a-pydantic-list-field-a-default-value
Example Code
Python, Pydantic & OS Version
Affected Components
.dict()
and.json()
construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: