[issue40595] AttributeError from type annotation

2020-05-15 Thread Ivan Levkivskyi
Ivan Levkivskyi added the comment: Yes, this is as expected. A recommended workaround is to define a type alias like `Match = re.Match` before the class body. You can also suppress the exception with `from __future__ import annotations` (so that the annotations are not evaluated), but

[issue40595] AttributeError from type annotation

2020-05-11 Thread Taylor Robie
Taylor Robie added the comment: Ah, I see. If this is intended behavior (which is sounds like it is?) feel free to close. Thanks! -- ___ Python tracker ___

[issue40595] AttributeError from type annotation

2020-05-11 Thread Eric V. Smith
Eric V. Smith added the comment: This is not an annotations-only issue. This is no different from: import re class MyClass(object): def re(self): pass m = re.Match Which gives the same error. It's being evaluated at class scope. -- nosy: +eric.smith

[issue40595] AttributeError from type annotation

2020-05-11 Thread Taylor Robie
New submission from Taylor Robie : Consider the following: ``` import re class MyClass(object): def re(self): pass def foo(self, m: re.Match): pass ``` Even though `re` and `MyClass.re` are distinct namespaces, the type annotation misses that fact (presumably there