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
This bug does not appear in pydantic==2.1.0 in python 3.8. This seems to be related to the introduction of __instancecheck__ in python 3.9.
In pydantic<=2.0.3 in python==3.9, there was no problem using a field that was a Generic w.r.t. a ParamSpec, but after pydantic==2.1.0, a RecursionError is now raised when defining a BaseModel with a field that uses a ParamSpec (or a GenericTypeAlias that uses a ParamSpec).
│ /Users/ringo/opt/anaconda3/envs/glass39/lib/python3.9/site-packages/pydantic/_internal/_generics │
│ .py:363 in <genexpr> │
│ │
│ 360 │ # Handle special case for typehints that can have lists as arguments. │
│ 361 │ # `typing.Callable[[int, str], int]` is an example for this. │
│ 362 │ if isinstance(type_, (List, list)): │
│ ❱ 363 │ │ if any(has_instance_in_type(element, isinstance_target) for element in type_): │
│ 364 │ │ │ return True │
│ 365 │ │
│ 366 │ return False │
│ │
│ /Users/ringo/opt/anaconda3/envs/glass39/lib/python3.9/site-packages/pydantic/_internal/_generics │
│ .py:363 in has_instance_in_type │
│ │
│ 360 │ # Handle special case for typehints that can have lists as arguments. │
│ 361 │ # `typing.Callable[[int, str], int]` is an example for this. │
│ 362 │ if isinstance(type_, (List, list)): │
│ ❱ 363 │ │ if any(has_instance_in_type(element, isinstance_target) for element in type_): │
│ 364 │ │ │ return True │
│ 365 │ │
│ 366 │ return False │
│ │
│ /Users/ringo/opt/anaconda3/envs/glass39/lib/python3.9/site-packages/pydantic/_internal/_generics │
│ .py:363 in <genexpr> │
│ │
│ 360 │ # Handle special case for typehints that can have lists as arguments. │
│ 361 │ # `typing.Callable[[int, str], int]` is an example for this. │
│ 362 │ if isinstance(type_, (List, list)): │
│ ❱ 363 │ │ if any(has_instance_in_type(element, isinstance_target) for element in type_): │
│ 364 │ │ │ return True │
│ 365 │ │
│ 366 │ return False │
│ │
│ /Users/ringo/opt/anaconda3/envs/glass39/lib/python3.9/site-packages/pydantic/_internal/_generics │
│ .py:362 in has_instance_in_type │
│ │
│ 359 │ │
│ 360 │ # Handle special case for typehints that can have lists as arguments. │
│ 361 │ # `typing.Callable[[int, str], int]` is an example for this. │
│ ❱ 362 │ if isinstance(type_, (List, list)): │
│ 363 │ │ if any(has_instance_in_type(element, isinstance_target) for element in type_): │
│ 364 │ │ │ return True │
│ 365 │
│ │
│ /Users/ringo/opt/anaconda3/envs/glass39/lib/python3.9/typing.py:719 in __instancecheck__ │
│ │
│ 716 │ │ else: │
│ 717 │ │ │ setattr(self.__origin__, attr, val) │
│ 718 │ │
│ ❱ 719 │ def __instancecheck__(self, obj): │
│ 720 │ │ return self.__subclasscheck__(type(obj)) │
│ 721 │ │
│ 722 │ def __subclasscheck__(self, cls): │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
RecursionError: maximum recursion depth exceeded
ringohoffman
changed the title
python>=3.9, pydantic>=2.1.0 regression in support for ParamSpec, RecursionError in model definition
python==3.9, pydantic>=2.1.0 regression in support for ParamSpec, RecursionError in model definition
Jul 27, 2023
@ringohoffman could you check if #6923 resolves your issue? It at least doesn't cause a recursion error but I'm not actually running any code with the relevant model.
Initial Checks
Description
This bug does not appear in
pydantic==2.1.0
in python 3.8. This seems to be related to the introduction of__instancecheck__
in python 3.9.In
pydantic<=2.0.3
in python==3.9, there was no problem using a field that was a Generic w.r.t. aParamSpec
, but afterpydantic==2.1.0
, aRecursionError
is now raised when defining aBaseModel
with a field that uses aParamSpec
(or aGeneric
TypeAlias
that uses aParamSpec
).Example Code
Python, Pydantic & OS Version
Selected Assignee: @adriangb
The text was updated successfully, but these errors were encountered: