While #1451 added support for forward references in the classes themselves, forward references in converter functions still fail due to the use of inspect.signature which by default uses Format.VALUE when getting annotations.
Example:
from attrs import define, field
@define
class Works:
x: unknown1
def converter(x: unknown2 | str) -> str:
return str(x)
@define
class Fails:
x: str = field(converter=converter)
Result:
NameError: name 'unknown2' is not defined
Cause:
|
self.sig = inspect.signature(callable) |
For Python 3.14 annotations you now need:
self.sig = inspect.signature(callable, annotation_format=annotationlib.Format.FORWARDREF)
While #1451 added support for forward references in the classes themselves, forward references in converter functions still fail due to the use of
inspect.signaturewhich by default usesFormat.VALUEwhen getting annotations.Example:
Result:
Cause:
attrs/src/attr/_compat.py
Line 50 in 1315e42
For Python 3.14 annotations you now need: