-
-
Notifications
You must be signed in to change notification settings - Fork 133
Closed
Description
When a parent class with a generics passed to include_subclasses, then:
- You need to specify the generic type, otherwise getting
E cattrs.errors.StructureHandlerNotFoundError: Missing type for generic argument T, specify it when structuring.
- If generic type is specified, you get the following issue
__________________________________________ ERROR collecting test_demo_bug.py __________________________________________
test_demo_bug.py:23: in <module>
include_subclasses(Parent[str], c)
.venv/lib/python3.13/site-packages/cattrs/strategies/_subclasses.py:72: in include_subclasses
parent_subclass_tree = tuple(_make_subclasses_tree(cl))
.venv/lib/python3.13/site-packages/cattrs/strategies/_subclasses.py:15: in _make_subclasses_tree
sscl for scl in cl.__subclasses__() for sscl in _make_subclasses_tree(scl)
/Users/.pyenv/versions/3.13.3/lib/python3.13/typing.py:1366: in __getattr__
raise AttributeError(attr)
E AttributeError: __subclasses__. Did you mean: '__subclasscheck__'?
Quick reproducer:
import abc
from typing import Generic, TypeVar
import attrs
import cattrs
from cattrs.strategies import include_subclasses
T = TypeVar("T")
@attrs.define()
class Parent(
Generic[T],
metaclass=abc.ABCMeta,
):
arg: T
class Child(Parent[str]): ...
c = cattrs.Converter()
# include_subclasses(Parent, c) - this fails with cattrs.errors.StructureHandlerNotFoundError Missing type for generic argument T, specify it when structuring.
include_subclasses(Parent[str], c)
def test_structuring():
assert c.structure({"arg": 5}, Child) == Child("5")Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels