- Notifications
You must be signed in to change notification settings - Fork 269
Closed
Description
ericvsmith/dataclasses#92 (comment) raised an important question (this existing problem is also mentioned in PEP 563). Currently, get_type_hints
will raise a NameError
in situations where it might not be the desired behaviour (e.g. if used by a class decorator). For example:
def modify(cls): types = get_type_hints(cls) # do something with 'cls' and 'types' return cls @modify class C: linked: 'C'
It looks like it will be useful to have an option to keep forward references that are currently undefined. For example:
class C: x: 'ClassVar[B]' assert get_type_hints(C, allow_forward=True) == {'x': ClassVar['B']} class B: ... assert get_type_hints(C, allow_forward=True) == {'x': ClassVar[B]}
patrick91 and antonagestam
Metadata
Metadata
Assignees
Labels
No labels