Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subclass registration of generic decorator class fails #1364

Closed
Darkdragon84 opened this issue Oct 25, 2024 · 2 comments
Closed

subclass registration of generic decorator class fails #1364

Darkdragon84 opened this issue Oct 25, 2024 · 2 comments

Comments

@Darkdragon84
Copy link

I am using the decorator pattern to create a decorator class Decorated from an abstract base class Base.

from attrs import define

@define
class Base:
    @abstractmethod
    def meth(self): ...

@define
class Decorated(Base):
    base: Base

    def meth(self): pass

Base has many more subclasses in addition and I use it as annotation in many places, so I would like to be able to register all subclasses of it to the converter. This works fine in the above example by e.g.

from cattrs import Converter
from cattrs.strategies import include_subclasses

converter = Converter()
include_subclasses(Base, converter)

However, I would now like to make Decorated generic on subclasses of Base:

from typing import Generic, TypeVar

@define
class Decorated(Base, Generic[T]):
    base: T

    def meth(self): pass

Now, when registering all subclasses of Base I get the error

cattrs.errors.StructureHandlerNotFoundError: Missing type for generic argument T, specify it when structuring.

This happens at registration time, not at (un)structuring time.

Is this expected? Can this be mitigated/circumvented?

@hynek
Copy link
Member

hynek commented Oct 26, 2024

dupe of python-attrs/cattrs#595

@hynek hynek closed this as not planned Won't fix, can't repro, duplicate, stale Oct 26, 2024
@Darkdragon84
Copy link
Author

oops, I guess I reported in the wrong repo, my bad 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants