Skip to content

Python 3.14 compatibility: AssertionError in converters due to __args__ changes #413

@tsuga

Description

@tsuga

Title

Python 3.14 compatibility: AssertionError in converters due to __args__ changes

Description

Environment

  • datafiles version: 2.4 (latest)
  • Python version: 3.14
  • OS: Ubuntu (GitHub Actions)

Problem

When using datafiles with Python 3.14, an AssertionError occurs during dataclass initialization. The error originates from converters/__init__.py where the code assumes cls.__args__ has exactly 2 elements.

Error Traceback

Traceback (most recent call last):
  File ".venv/bin/build-resume-all", line 10, in <module>
    sys.exit(build_resume_all())
  File "resume_cv_2/runner.py", line 144, in build_resume_all
    _build_resume(primary=True, others=True)
  File "resume_cv_2/runner.py", line 102, in _build_resume
    context = Content("default", Missing, Missing, Missing, Missing, Missing)
  File ".venv/lib/python3.14/site-packages/datafiles/model.py", line 84, in modified_init
    Model.__post_init__(self)
  File ".venv/lib/python3.14/site-packages/datafiles/model.py", line 20, in __post_init__
    object.__setattr__(self, "datafile", create_mapper(self))
  File ".venv/lib/python3.14/site-packages/datafiles/mapper.py", line 304, in create_mapper
    attrs[field.name] = map_type(field.type, name=field.name)
  File ".venv/lib/python3.14/site-packages/datafiles/converters/__init__.py", line 56, in map_type
    converters[field.name] = map_type(field.type, name=field.name)
  File ".venv/lib/python3.14/site-packages/datafiles/converters/__init__.py", line 64, in map_type
    assert len(cls.__args__) == 2
           ^^^^^^^^^^^^^^^^^^^^^^
AssertionError

Root Cause

Python 3.14 introduces changes to type annotation internals (related to PEP 649 and PEP 749). The __args__ attribute on generic types may have a different structure than in previous Python versions.

The assertion at converters/__init__.py:64 expects exactly 2 type arguments, but Python 3.14's type system may represent the same types differently.

Workaround

Currently using Python 3.13, which works correctly.

Additional Context

  • Similar issues have been reported in other libraries using type introspection (Pydantic, Flax, etc.)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions