[New-bugs-announce] [issue40595] AttributeError from type annotation

Taylor Robie report at bugs.python.org
Mon May 11 13:19:58 EDT 2020


New submission from Taylor Robie <taylor.aiken.robie at gmail.com>:

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 is an issue with how it is parsing the AST) and attempts to access MyClass.re.Match, resulting in:

`AttributeError: 'function' object has no attribute 'Match'`

Commenting out the definition of `MyClass.re` or reversing the definition order resolves the issue.

----------
components: Interpreter Core
messages: 368635
nosy: robieta
priority: normal
severity: normal
status: open
title: AttributeError from type annotation
type: behavior
versions: Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40595>
_______________________________________


More information about the New-bugs-announce mailing list