Skip to content

python3.14 compat#5859

Merged
adhami3310 merged 17 commits intomainfrom
masenf/python3.14-compat
Oct 8, 2025
Merged

python3.14 compat#5859
adhami3310 merged 17 commits intomainfrom
masenf/python3.14-compat

Conversation

@masenf
Copy link
Copy Markdown
Collaborator

@masenf masenf commented Oct 8, 2025

Compatibility for python3.14 (released October 7, 2025)

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Summary

This PR adds Python 3.14 compatibility to the Reflex framework following Python 3.14's release on October 7, 2025. The changes primarily address PEP 649 (Deferred Evaluation of Annotations), which fundamentally changes how type annotations are handled in Python 3.14.

The core technical changes involve replacing direct __annotations__ access with proper annotation resolution mechanisms:

  1. Type Hint Resolution: Multiple files now use get_type_hints() from the typing module instead of directly accessing __annotations__, ensuring forward references are properly resolved

  2. Lazy Annotations Support: Several metaclasses and utility functions now check for the new __annotate_func__ attribute introduced in Python 3.14, which provides deferred annotation evaluation

  3. Bytecode Compatibility: The dependency tracking system has been updated to handle the new LOAD_FAST_BORROW bytecode opcode introduced in Python 3.14

  4. Build Environment: CI workflows have been updated to test against Python 3.14, and PyO3 compatibility has been ensured through environment variable configuration

These changes maintain full backward compatibility with older Python versions while enabling the framework to work with Python 3.14's new annotation system. The modifications span critical areas including state management, model definitions, field resolution, and the build pipeline.

Important Files Changed

Changed Files
Filename Score Overview
reflex/utils/pyi_generator.py 5/5 Replaces direct __annotations__ access with get_type_hints() for Python 3.14 compatibility
reflex/components/field.py 5/5 Adds support for Python 3.14's __annotate_func__ lazy annotation mechanism in metaclass
reflex/state.py 5/5 Updates computed variable shadow checking to use get_type_hints() instead of direct annotation access
reflex/vars/base.py 5/5 Implements Python 3.14 lazy annotation support in BaseStateMeta metaclass
reflex/vars/dep_tracking.py 5/5 Adds support for new LOAD_FAST_BORROW bytecode opcode in dependency tracking
reflex/base.py 5/5 Applies new ModelMetaclassLazyAnnotations metaclass for Python 3.14 compatibility
reflex/model.py 5/5 Updates deprecation version from 0.8.0 to 0.8.15 for primary key override warning
.github/workflows/unit_tests.yml 4/5 Adds Python 3.14 to CI matrix but inconsistent between jobs (main vs macOS)
.github/workflows/integration_tests.yml 4/5 Adds Python 3.14 to some test jobs but not others, creating incomplete coverage
.github/actions/setup_build_env/action.yml 4/5 Adds PyO3 forward compatibility environment variable for Python 3.14 support

Confidence score: 4/5

  • This PR is safe to merge with minimal risk as it implements well-established compatibility patterns for Python version upgrades
  • Score reflects thorough compatibility implementation across critical components, with only minor CI workflow inconsistencies
  • Pay close attention to the GitHub Actions workflow files which have incomplete Python 3.14 coverage across all test jobs

Additional Comments (1)

  1. .github/workflows/unit_tests.yml, line 80 (link)

    style: The macOS unit tests job doesn't include Python 3.14, creating inconsistent test coverage. Consider adding '3.14' here to match the main unit-tests job.

10 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Oct 8, 2025

CodSpeed Performance Report

Merging #5859 will improve performances by 27.84%

Comparing masenf/python3.14-compat (36d045f) with main (cdfa8b5)

Summary

⚡ 8 improvements

Benchmarks breakdown

Benchmark BASE HEAD Change
test_compile_page[_complicated_page] 90 ms 65.5 ms +37.42%
test_compile_page[_stateful_page] 10.5 ms 7.7 ms +36.68%
test_compile_stateful[_complicated_page] 603.9 µs 457.8 µs +31.94%
test_compile_stateful[_stateful_page] 147.1 µs 115 µs +27.84%
test_get_all_imports[_complicated_page] 22.6 ms 16.3 ms +38.71%
test_get_all_imports[_stateful_page] 3 ms 2.2 ms +36.75%
test_evaluate_page[_complicated_page] 50.4 ms 37.2 ms +35.21%
test_evaluate_page[_stateful_page] 6.5 ms 4.9 ms +32.49%

adhami3310
adhami3310 previously approved these changes Oct 8, 2025
@masenf
Copy link
Copy Markdown
Collaborator Author

masenf commented Oct 8, 2025

turns out there actually is a nice api for this, will update

@masenf masenf force-pushed the masenf/python3.14-compat branch from 44046af to 2448c78 Compare October 8, 2025 17:02
@adhami3310 adhami3310 merged commit 3ef3929 into main Oct 8, 2025
47 checks passed
@adhami3310 adhami3310 deleted the masenf/python3.14-compat branch October 8, 2025 19:55
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