[issue44192] Annotations, Inheritance and Circular Reference
Filipe Laíns
report at bugs.python.org
Mon May 24 14:22:47 EDT 2021
Filipe Laíns <lains at riseup.net> added the comment:
The annotations will effectively become strings, instead of object references, in Python 3.11, which solves this issue.
You can enable this behavior in holder Python version with `from __future__ import annotations`, see PEP 563[1].
>>> class Base:
... _sub: list[Sub]
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in Base
NameError: name 'Sub' is not defined
>>> from __future__ import annotations
>>> class Base:
... _sub: list[Sub]
...
>>> class Sub:
... _parent: Base
...
>>>
[1] https://www.python.org/dev/peps/pep-0563/
----------
nosy: +FFY00
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44192>
_______________________________________
More information about the Python-bugs-list
mailing list