This PEP doesn't cover about what happened when __co_annotation__()
failed (e.g. NameError).
Forward reference is a major reason, but not a only reason for using
string annotation. There are two other reasons:
* Avoid importing heavy module.
* Avoid circular imports.
In these cases, this pattern is used:
```
from __future__ import annotations
import typing
from dataclasses import dataclass
if typing.TYPE_CHECKING:
import other_mod # do not want to import actually
@dataclass
class Foo:
a: other_mod.spam
b: other_mod.ham
def fun(a: other_mod.spam, b: other_mod.ham) -> None: ...
```
Of course, mypy works well with string annotation because it is static checker.
IPython shows signature well too:
```
In [3]: sample.Foo?
Init signature: sample.Foo(a: 'other_mod.spam', b: 'other_mod.ham') -> None
Docstring: Foo(a: 'other_mod.spam', b: 'other_mod.ham')
```
PEP 563 works fine in this scenario. How PEP 649 works?
Regards,
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/YMMYKST2B4IJJOHAQIFIBAT57MKBBG56/
Code of Conduct: http://python.org/psf/codeofconduct/