-
Consider the following self-referencing type alias, defined for JSON-able objects (see this post for reference):
I am kinda new to Pydantic, so not pretty sure if this is supported. But apparently the following code snippet did not work for me. I'm using Python 3.10.2 with pydantic 1.10.7.
The following error was thrown:
Seems like it hits the max recursion depth of Python when trying to deal with the Thanks for the help in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The short answer is — not yet. But it's something we do want to add support for. Once the type alias syntax introduced in this PEP https://peps.python.org/pep-0695/#generic-type-alias is introduced, I think that will be the obvious way to handle it, though that will require python 3.12+. Also, it looks like there is active work toward backporting the For what it's worth, I think the pydantic implementation will probably look a lot like this: ef5dd26 which was part of an attempt I gave up on after subsequently reworking it to try to automatically infer the alias name, which was misguided.) So basically, stay tuned! |
Beta Was this translation helpful? Give feedback.
The short answer is — not yet. But it's something we do want to add support for.
Once the type alias syntax introduced in this PEP https://peps.python.org/pep-0695/#generic-type-alias is introduced, I think that will be the obvious way to handle it, though that will require python 3.12+.
Also, it looks like there is active work toward backporting the
TypeAliasType
intotyping_extensions
, and once it is added, I think that will be the obvious way to support it in earlier python versions. See python/typing_extensions#159 and python/typing_extensions#160 for reference.For what it's worth, I think the pydantic implementation will probably look a lot like this: ef5dd26 which was part of an at…