Types Hints are an optional feature of Python. This also means, that using @dataclass
does not require from you to define types.
In the annotation you can write many things. These are not checked if you don't want them to be checked. These examples work:
@dataclass
class ColoredObject:
color : ""
name : ""
@dataclass
class ColoredObject:
color : ...
name : ...
@dataclass
class ColoredObject:
color : True
name : True
@dataclass
class ColoredObject:
color : object
name : object
@dataclass
class ColoredObject:
color : None
name : None
I listed so many options here so that you can decide if you like some of them or not. It is your decision how you use code annotations.
For people who are used to languages that are more statically typed than Python, this may be an awkward style. It looks like abusing an empty string or the Ellipse object for this purpose. And that is true. But keep in mind that code readability is also important in programming. Interestingly most readers of your code would intuitively understand if you write ...
without even knowing that there exists something like an Ellipse object.
Of course if you don't want to confuse people who prefer type hints or if you want to use tools that expect correct type hints, you must establish an agreement on this.
The solution with typing.Any
I have not listed. Of course that is a good solution. But types are an optional feature of Python. And that also means that knowing that there is something like typing.Any
is optional knowledge.