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
I have searched Google & GitHub for similar requests and couldn't find anything
I have read and followed the docs and still think this feature is missing
Description
For pydantic, generic type information is needed at runtime. Thus, we must recieve type as a function argument and pass as generic type to create generic pydantic model. However, the code bellow causes error on mypy:
frompydanticimportBaseModelclassC[T](BaseModel): ...
deff[T](t: type[T]) ->C[T]:
returnC[t]() # b.py:8: error: Variable "t" is not valid as a type [valid-type]
This issue is also known on mypy, because pyright does not cause this error, though mypy does not fix it for a long time.
Probably, this problem occurs only with libraries using generic type at runtime, such as Pydantic. I think a solution with the mypy plugin provided by pydantic could be considered.
I'm sorry if it is impossible, I do not know much about mypy plugin limitation.
I think a solution with the mypy plugin provided by pydantic could be considered.
It is not the job of the Pydantic plugin to fix non Pydantic-related issues. It is probably also not be possible to do so, as the mypy plugin interface exposes limited capabilities, and this issue is probably present in mypy's core logic.
Initial Checks
Description
For pydantic, generic type information is needed at runtime. Thus, we must recieve type as a function argument and pass as generic type to create generic pydantic model. However, the code bellow causes error on mypy:
This issue is also known on mypy, because pyright does not cause this error, though mypy does not fix it for a long time.
Probably, this problem occurs only with libraries using generic type at runtime, such as Pydantic. I think a solution with the mypy plugin provided by pydantic could be considered.
I'm sorry if it is impossible, I do not know much about mypy plugin limitation.
Thanks!
Affected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: