[issue43746] Weird typing annotation closure behavior

conchylicultor report at bugs.python.org
Tue Apr 6 07:45:28 EDT 2021


conchylicultor <etiennefg.pot at gmail.com> added the comment:

Interestingly mypy, pylint correctly resolve the closure.

```
class A:
    dataclasses: dataclasses.Field = dataclasses.field()

A.dataclasses.other  # mypy error: "Field[Any]" has no attribute "other"
```

So the current workaround is to use quotes:

```
class A:
  # Type correctly inferred and no closure runtime error
  losses: 'losses.Losses' = losses.Losses()
```

----------

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


More information about the Python-bugs-list mailing list