I would have to disagree with this post (first point is actually inaccurate and the second I could go either way on). Type annotations/mypy, especially when coupled with dataclasses/pydantic has been very helpful in maintaining a rather substantial 3.7 codebase.
> rather substantial 3.7 codebase What size codebase is substantial?
A Failed Experiment with Python Type Annotations
81–82 of 82 posts
Re: A Failed Experiment with Python Type Annotations
#82Earlier quoted context omitted.
OK, that works, but it does seem dumb, or even deliberately obtuse. The language could just as well recognize Node as it recognizes 'Node', but instead it given as a burden for the human programmer to handle. Is it maybe because mypy is not really part of the Python language , and can't really make changes to it?
This is not mypy, it's "python-the-language": the annotations are values, and, in this case, the method annotations are evaluated when encountered - which is before the end of the class. So you are trying to use a value still not defined. It's like doing something like def foo() -> Bar: ... class Bar: ... obviously the python interpreter cannot find a "Bar" definition during the parsing of the foo function
I'm saying the language could work differently.
The case of referring to a class inside its definition is quite different from your "Bar" case. The thing referred to is already declared, it's just not fully defined yet.
There is no logical reason I can see making it impossible for Python to honor the obvious intention of the programmer here. It seems it has just chosen not to do so. Though I'll admit I haven't thought through every weird corner case :)