python-attrs / python-attrs/attrs
Support 3.14 annotations in converter functions
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 480
- Avg merge
- 2h 15m
- Merged PRs (30d)
- 2
Description
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
For Python 3.14 annotations you now need:
self.sig = inspect.signature(callable, annotation_format=annotationlib.Format.FORWARDREF)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/attr/_compat.py at the inspect.signature call linked in the issue, then reproduce the Fails example with the converter annotation. Confirm that the converter accepts unresolved forward references under Python 3.14 without raising NameError; the issue does not name a specific test file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100