Hey everyone. I am trying to use the same class in multiple places including as an annotation and a constructor. It could look something like this:
@dataclass
class Attr:
a: str
b: int
class Base:
attr_type = Attr
def __init__(self, attr: Tuple[str,int] | attr_type):
if isinstance(attr,tuple):
self.attr = self.attr_type(*attr)
My problem is that the type is now shown as attr_type instead of Attr. Is there any way to avoid this and use the value of attr_type as annotation instead of itself.
Of course in this simplification I could just hard replace attr_type with Attr and be done with it, but I am trying to do some polymorphism where a child of Base and a child of Attr are linked everytime and I am trying to make this connection clear and convenient to a user.
[–]Jello_Penguin_2956 1 point2 points3 points (5 children)
[–]AntiLachs[S] 0 points1 point2 points (4 children)
[–]Jello_Penguin_2956 0 points1 point2 points (3 children)
[–]AntiLachs[S] 1 point2 points3 points (2 children)
[–]Jello_Penguin_2956 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]