{"id":"2923991ea67cf2b4","repo":"pydantic/pydantic","slug":"e-args-0-if-you-made-use-of-an-implicit-recursi","errorCode":null,"errorMessage":"{e.args[0]}\nIf you made use of an implicit recursive type alias (e.g. `MyType = list['MyType']), consider using PEP 695 type aliases instead. For more details, refer to the documentation: https://pydantic.dev/docs/validation/{version_short()}/concepts/types/#named-recursive-types","messagePattern":"(.+?)\nIf you made use of an implicit recursive type alias \\(e\\.g\\. `MyType = list\\['MyType'\\]\\), consider using PEP 695 type aliases instead\\. For more details, refer to the documentation: https://pydantic\\.dev/docs/validation/(.+?)/concepts/types/#named-recursive-types","errorType":"exception","errorClass":"RecursionError","httpStatus":null,"severity":"error","filePath":"pydantic/_internal/_typing_extra.py","lineNumber":392,"sourceCode":"            message = f'Unable to evaluate type annotation {value.__forward_arg__!r}.'\n        else:\n            message = f'Unable to evaluate type annotation {value!r}.'\n        if sys.version_info >= (3, 11):\n            e.add_note(message)\n            raise\n        else:\n            raise TypeError(message) from e\n    except RecursionError as e:\n        message = (\n            \"If you made use of an implicit recursive type alias (e.g. `MyType = list['MyType']), \"\n            'consider using PEP 695 type aliases instead. For more details, refer to the documentation: '\n            f'https://pydantic.dev/docs/validation/{version_short()}/concepts/types/#named-recursive-types'\n        )\n        if sys.version_info >= (3, 11):\n            e.add_note(message)\n            raise\n        else:\n            raise RecursionError(f'{e.args[0]}\\n{message}')\n\n\n@deprecated(\n    '`eval_type_lenient()` is deprecated, use `try_eval_type()` instead.',\n    category=None,\n)\ndef eval_type_lenient(\n    value: Any,\n    globalns: GlobalsNamespace | None = None,\n    localns: MappingNamespace | None = None,\n) -> Any:  # pragma: no cover\n    ev, _ = try_eval_type(value, globalns, localns)\n    return ev\n\n\ndef _eval_type(\n    value: Any,\n    globalns: GlobalsNamespace | None = None,","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/pydantic/pydantic/blob/2e5f0e2b4218de31709f1cf9c5bc61ea97a68835/pydantic/_internal/_typing_extra.py#L374-L410","documentation":"A `RecursionError` (with a note pointing to PEP 695) re-raised from `eval_type` when forward-reference evaluation blows the recursion limit. The classic cause is an implicit recursive type alias such as `MyType = list['MyType']`, where resolving the alias references itself indefinitely under the legacy alias semantics.","triggerScenarios":"Defining `MyType = list['MyType']` (pre-PEP-695 style) and using it on a Pydantic field. Each evaluation of the alias re-substitutes itself, recursing until the interpreter's limit is hit.","commonSituations":"Building tree/graph/JSON-like recursive structures; porting recursive type aliases between Python versions; using older tutorials that predate PEP 695.","solutions":["Switch to a PEP 695 type alias: `type MyType = list['MyType']` (lazy, recursion-safe).","Alternatively model the recursion with a self-referencing BaseModel: `class Node(BaseModel): children: list['Node']`.","If you must use the legacy form, make the alias refer to a forward-ref class name rather than to itself."],"exampleFix":"# before\nMyType = list['MyType']   # implicit recursive alias\n\nclass M(BaseModel):\n    x: MyType   # RecursionError\n\n# after (PEP 695, Python 3.12+)\ntype MyType = list['MyType']\nclass M(BaseModel):\n    x: MyType","handlingStrategy":"validation","validationCode":null,"typeGuard":"import sys\ndef safe_alias_eval(alias_str, ns):\n    sys.setrecursionlimit(200)\n    try:\n        eval(alias_str, ns)\n        return True\n    except RecursionError:\n        return False","tryCatchPattern":null,"preventionTips":["Prefer PEP 695 `type` aliases for recursive types.","Model graph/tree structures with self-referencing BaseModels.","Test recursive type definitions in isolation before wiring them in."],"tags":["pydantic","typing","recursion","type-aliases","pep695"],"analyzedSha":"2e5f0e2b4218de31709f1cf9c5bc61ea97a68835","analyzedAt":"2026-08-04T19:54:21.281Z","schemaVersion":2}