Seems like TypeAliasType would be a more friendly solution to solve this pattern. A quick tests shows that the only thing that is lost (which is not even being used at the moment) is the title of the root model on model construction.
Additionally, the TypeAliasType class does not seem to be importable from the typing module in 3.11 despite what is written in the OP, instead it must be imported from typing_extensions as of 3.11.
Following https://github.com/pydantic/pydantic/discussions/10635#discussioncomment-10970037
Seems like
TypeAliasType
would be a more friendly solution to solve this pattern. A quick tests shows that the only thing that is lost (which is not even being used at the moment) is the title of the root model on model construction.Additionally, the
TypeAliasType
class does not seem to be importable from thetyping
module in 3.11 despite what is written in the OP, instead it must be imported fromtyping_extensions
as of 3.11.