Python 3.14 in Production: What PEP 649 Actually Breaks
Blog post from Mergify
PEP 649 in Python 3.14 introduces deferred evaluation of annotations, eliminating the need for quoted annotations and the "from __future__ import annotations" directive, thereby simplifying code maintenance. This change, however, causes issues for frameworks like FastAPI, which inspect annotations at runtime, as deferred annotations require runtime resolution of types, leading to NameError if TYPE_CHECKING imports are used. The solution involves updating to FastAPI 0.128.1, which supports PEP 649 by using a special forward-reference mode to handle annotations, but this update requires careful ordering in the migration process to prevent runtime errors. The real challenge lies in ensuring all dependencies in the codebase support the new annotation processing mode, highlighting the need for a comprehensive audit of the dependency chain before fully adopting Python 3.14.