I am trying to generate a UML diagram for a class that uses Unions and List typehints.
An example of it would be
from dataclasses import dataclass
from typing import Union
@dataclass
class ClassA:
name: str
@dataclass
class ClassB:
an_attribute: int
@dataclass
class ClassC:
my_class: Union[ClassA, ClassB]
When running pyreverse -ASmn stackoverflow_example.py -o png I obtain an UML not showing usages of classA and classB:
If I replace the code in ClassC to
@dataclass
class ClassC:
my_class: ClassA
Then I get an UML description closer to my goal:

But of course, this means that when I assign something of type ClassB to my_class I get a warning highlighted, which is exactly what it should do.
My understanding of how the Union should work is that I would get something like this:

The example shows Union, but List and others will have similar behaviours.
Is there a way of doing this, or is this a design that shouldn't be done?


