Skip to content

fix: support Python 3.14 annotations in assign_attr_with_json#69

Open
stefefn wants to merge 1 commit into
sun-guannan:devfrom
stefefn:fix/python314-annotations
Open

fix: support Python 3.14 annotations in assign_attr_with_json#69
stefefn wants to merge 1 commit into
sun-guannan:devfrom
stefefn:fix/python314-annotations

Conversation

@stefefn
Copy link
Copy Markdown

@stefefn stefefn commented May 13, 2026

Problem

On Python 3.14, saving a draft crashes with KeyError fps inside assign_attr_with_json in pyJianYingDraft/util.py.

Python 3.14 introduced deferred annotation evaluation (PEP 649), which means class-level annotations are no longer automatically stored in cls.dict. The existing code relied on this, so type_hints was always empty and any attribute lookup raised a KeyError.

Fix

Replace the manual dict loop with inspect.get_annotations(cls), which is the correct cross-version API for reading class annotations. inspect was already imported in the file so no new dependency is needed.

Testing

Verified on Python 3.14.4 (WSL/Ubuntu). Draft creation, add_video, and save_draft all complete successfully after the fix.

Python 3.14 (PEP 649) no longer populates cls.__dict__["__annotations__"]
for lazily-evaluated annotations, causing a KeyError when loading drafts.

Replace the manual __dict__ lookup with inspect.get_annotations(cls),
which works correctly across Python 3.10+.
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.

1 participant