Skip to content

fix: support deferred class annotations on Python 3.14 - #1975

Open
Excelius-Wang wants to merge 1 commit into
IBM:mainfrom
Excelius-Wang:fix/python-314-dataclass-annotations
Open

fix: support deferred class annotations on Python 3.14#1975
Excelius-Wang wants to merge 1 commit into
IBM:mainfrom
Excelius-Wang:fix/python-314-dataclass-annotations

Conversation

@Excelius-Wang

Copy link
Copy Markdown

Summary

  • resolve dataclass annotations from the created class instead of the class-body namespace
  • use Format.FORWARDREF on Python 3.14 to support unresolved and self-referencing annotations
  • preserve compatibility with Python 3.8–3.13
  • handle both classes and instances passed to to_dict(classes=...)

Closes #1974

Testing

  • Python 3.14.6: import unitxt
  • Python 3.14.6: python -m unittest tests.library.test_dataclass — 21 passed
  • Python 3.12.4: python -m unittest tests.library.test_dataclass — 20 passed, 1 skipped
  • simulated Python 3.8/3.9 annotation-inspection path — 20 passed, 1 skipped
  • pre-commit run --files src/unitxt/dataclass.py tests/library/test_dataclass.py

Signed-off-by: Excelius <57819425+Excelius-Wang@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

import unitxt fails on Python 3.14: get_fields reads __annotations__ from the class namespace (PEP 649)

1 participant