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
I suggest adopting (either by adding a dependency or, more safely, incorporating into pydantic internally) a PEP 585 (allow subscripting built-in generic types, e.g. dict[str, int]) and PEP 604 (X | Y union type syntax) backport for Python <3.10 runtime type evaluation, so that the freshest type hinting style can be used for pydantic models, without having to import the deprecated type aliases from typing.
If this feature request is accepted, the developers that use pydantic, could ditch the old, confusing for Python beginners, type hinting format:
The new fashion of type hints is broadly used for example in pandas (pandas.DataFrame.__init__—very likely people would see it often), poetry, FastUI and many, many more modern projects that do support Python 3.8+ already. But only in the typing scope that doesn't get evaluated at runtime—this feature request aims to open up a possibility to migrate the codebase fully to the newest fashion.
I am suggesting it mainly because I know it is doable by altering the namespaces used by ForwardRef's with the help of AST—and would love to see it as a default behavior of pydantic. I could work on it, document it and test it against built-in types and pydantic extra types.
Initial Checks
Description
I suggest adopting (either by adding a dependency or, more safely, incorporating into pydantic internally) a PEP 585 (allow subscripting built-in generic types, e.g.
dict[str, int]
) and PEP 604 (X | Y
union type syntax) backport for Python <3.10 runtime type evaluation, so that the freshest type hinting style can be used for pydantic models, without having to import the deprecated type aliases fromtyping
.If this feature request is accepted, the developers that use pydantic, could ditch the old, confusing for Python beginners, type hinting format:
and use the newest, prettiest & recommended one:
in Python 3.8 and 3.9.
The new fashion of type hints is broadly used for example in pandas (
pandas.DataFrame.__init__
—very likely people would see it often), poetry, FastUI and many, many more modern projects that do support Python 3.8+ already. But only in the typing scope that doesn't get evaluated at runtime—this feature request aims to open up a possibility to migrate the codebase fully to the newest fashion.I am suggesting it mainly because I know it is doable by altering the namespaces used by ForwardRef's with the help of AST—and would love to see it as a default behavior of pydantic. I could work on it, document it and test it against built-in types and pydantic extra types.
Merry Christmas! 🎄
Affected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: