2 Jun
2021
2 Jun
'21
3:05 p.m.
I find that these annotations are typically unnecessary, at least when using pyright or mypy. I'm not sure about other Python type checkers. When pyright sees an unannotated `self` or `cls` parameter, it infers its type to be an internally-synthesized TypeVar that is bound to the parent class. If that method then returns `self` or `cls` or `cls()`, it infers the proper return type. It appears that mypy does something similar. Because of this behavior, I rarely need to annotate `self` or `cls` explicitly in my code. It's still required in overloads or in stub files because the return type cannot be inferred without the function's implementation. -Eric -- Eric Traut Contributor to Pyright & Pylance Microsoft Corp