Add type hints to a class
Level: Intermediate (score: 3)
In this Bite you'll add type hints to the provided Employee
class, making the code more explicit and improving type checking, readability, and static analysis support.
Type hints provide clarity on the expected types of class attributes and method arguments.
In addition, the optional use of dataclass
simplifies the class by automatically generating the constructor (__init__
), __repr__
, and equality methods (see also Newbie Bite 39).
However, the dataclass
is not required—manual definition of the __init__
method can be retained if preferred, and type hints can still be applied in either case.