Suppose I have the following class
<code>class MyClass:
def __init__(self, ...):
self.attr1: Union[Attr11, Attr12]
self.attr2: Literal["val1", "val2", "val3"]
self.attr3: Attr3
...
self.attrn: Attrn
</code>
<code>class MyClass:
def __init__(self, ...):
self.attr1: Union[Attr11, Attr12]
self.attr2: Literal["val1", "val2", "val3"]
self.attr3: Attr3
...
self.attrn: Attrn
</code>
class MyClass:
def __init__(self, ...):
self.attr1: Union[Attr11, Attr12]
self.attr2: Literal["val1", "val2", "val3"]
self.attr3: Attr3
...
self.attrn: Attrn
I am interested in the following type hint:
<code>if self.attr2 == "val1":
# self.attr1 should be Attr11 here
else:
# self.attr1 should be Attr12 here
</code>
<code>if self.attr2 == "val1":
# self.attr1 should be Attr11 here
else:
# self.attr1 should be Attr12 here
</code>
if self.attr2 == "val1":
# self.attr1 should be Attr11 here
else:
# self.attr1 should be Attr12 here
How can I do it?
7