Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.7k
Comments
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Uh oh!
There was an error while loading.Please reload this page.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
tamird commentedDec 16, 2024
@alejsdev could you please take a look? This is relatively trivial. |
This comment was marked as outdated.
This comment was marked as outdated.
Uh oh!
There was an error while loading.Please reload this page.
tamird commentedJan 13, 2025
@Kludex thanks for the approval. Are you able to land this please? |
Kludex commentedJan 13, 2025
No. I don't merge PRs. |
tamird commentedFeb 5, 2025
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
pydantic.mypy plugin
YuriiMotov left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM
Maybe we should extract the part related to plugin installation into a separate PR, but doesn't seem critical to me
tamird commentedJul 10, 2025
Thank you@YuriiMotov. Are you planning to merge this? |
pydantic.mypy pluginpydantic.mypy plugin📝 Docs preview for commit21c8f18 at:https://c3a1493f.fastapitiangolo.pages.dev |
pydantic.mypy plugin
svlandeg left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ok, so in an attempt to get this merged, I've moved the pydantic.mypy plugin changes to a separate PR#14081. This makes it easier to review which changes are causing what, as several reviewers had questions about what exactly is needed and what relates to what.
For this PR, the goal is simply to update tomypy 1.14.1. When doing so, we're getting 2 similar errors:
fastapi\encoders.py:244: error: Argument 1 to "asdict" has incompatible type "DataclassInstance | type[DataclassInstance]"; expected "DataclassInstance" [arg-type]What happens here is that first, we're callingdataclasses.is_dataclass(obj).
Due tothe typing of this method in theirdataclasses.pyi,mypy will go and typeobj asDataclassInstance | type[DataclassInstance]. This then doesn't align with the signature of the followingdataclasses.asdict(obj) statement, which expects aDataclassInstance.
So, these are the possible fixes for this:
- add an ignore statement
- add a
type()call before callingis_dataclass, as@tamird suggests. This isn't actually necessary, because the implementation ofdataclasses.is_dataclasswill calltype()when necessary. However, by doing this, we trickmypyinto assuming thatobjis NOT atype[DataclassInstance]and then it won't error on the followingasdictcall - inbetween the original
is_dataclasscheck and theasdictcall, add the following:assert not isinstance(obj, type). This again will tellmypynot to assume theobjis a type. To me, this is the most direct/clear solution, but I think it's a matter of taste.
Will run this by Tiangolo to get his opinion.
tiangolo commentedSep 20, 2025
Thanks a lot for the investigation and clarification with all the context@svlandeg! Yep, it makes more sense to me to use |
tiangolo left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Nice, thanks! 🚀
And thanks@svlandeg for the analysis, discussion and work on this! 🙌
a95e91e intofastapi:masterUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Depends on#12971.