Skip to content

Conversation

justinpolygon
Copy link
Collaborator

This PR addresses the breakage reported in #902, where Python 3.14's deferred annotation evaluation change (PEP 649) causes a KeyError when importing modules like RESTClient due to direct access to cls.__dict__["__annotations__"].

Background:

In Python 3.14, PEP 649 changes how type annotations are handled: they are now evaluated lazily (deferred) rather than eagerly at definition time. Annotations are stored internally via a new __annotate__ function (not for direct use), and the __annotations__ attribute is a descriptor that computes the annotation dictionary on access. This improves performance but alters runtime behavior. So, we currently directly check cls.__dict__["__annotations__"] and it fails in 3.14 with KeyError because __annotations__ is no longer a key in the class's __dict__ since it's a computed property.

Changes:

  • Updated modelclass to use typing.get_type_hints(cls) for version-agnostic annotation retrieval. This evaluates annotations on-demand in 3.14 while working identically in older versions (3.8+).
  • Corrected the attribute filtering logic: The original inspect.isroutine(a) (with a as str) always passed; now checks the actual class attribute to exclude methods properly.
  • No impact on existing functionality.

Testing:

  • Tested via Docker across Python 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, and 3.14 with aggs endpoint samples.
  • Verified no regressions in positional/keyword init for models like Agg.
  • Confirmed fix resolves import errors in 3.14.
  • Backwards Compatibility is fully preserved.

@justinpolygon justinpolygon merged commit 1b75d9a into master Oct 15, 2025
9 checks passed
@justinpolygon justinpolygon deleted the fix/python-3.14-annotations-compatibility branch October 15, 2025 16:52
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.

2 participants