Re:A Failed Experiment with Python Type Annotations
by _ZeD_ on Wednesday June 12, 2019 @01:24AM
(#20161993)
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
obviously the python interpreter cannot find a "Bar" definition during the parsing of the foo function
[ Parent
| on HN ]
Re:A Failed Experiment with Python Type Annotations
by BurningFrog on Friday June 14, 2019 @12:18PM
(#20184192)
You're saying this is how the language works.
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 :)