Code: Select all
class MyClass:
def __init__(self, ...):
self.attr1: Union[Attr11, Attr12]
self.attr2: Literal["val1", "val2", "val3"]
self.attr3: Attr3
...
self.attrn: Attrn
Code: Select all
if self.attr2 == "val1":
# self.attr1 should be Attr11 here
else:
# self.attr1 should be Attr12 here