attrs
attrs copied to clipboard
`typing.get_type_hints` cannot resolve forward references in `cls.__init__` annotations
The is related to #593/#760. Because #760 populates the generated __init__ method's globals at the time that the class is created, new globals aren't visible to get_type_hints by default.
Example code demonstrating this:
import attrs
import typing
@attrs.define
class HasForwardRef:
ref: "ClassDefinedLater"
class ClassDefinedLater:
pass
typing.get_type_hints(HasForwardRef.__init__)
This last call raises an error.
I've got a workaround for this in the code where I hit this, but it really wasn't obvious at first what was going on.
I'm not sure what to do about this – is it fixable yet at all?