Top New Features in Python 3.15: Lazy Imports, Faster JIT, Better Errors, Smarter Profiling
Python 3.15’s beta introduces lazy imports, a built‑in frozendict, a sentinel type, a low‑overhead statistical profiler, an upgraded JIT with 8‑13% speed gains, clearer error messages, type‑system tweaks, new list‑comprehension unpacking syntax, and a rollback to generational garbage collection.
Python 3.15’s first full release is one of the most feature‑rich versions of the language, bringing a suite of long‑awaited enhancements.
Lazy Import
The new lazy‑import syntax lets modules be imported only when their code is actually executed, reducing start‑up time for heavy imports. Developers can use the explicit lazy‑import statement or enable it via an environment variable, and the behavior matches normal imports without drawbacks.
Built‑in frozendict
A new immutable, hashable dictionary type called frozendict behaves like a regular dict but cannot be modified, allowing it to be used safely as a key in other dictionaries.
Built‑in sentinel() Type
Python now provides a sentinel() factory that creates unique objects (e.g., None, object(), sentinel("NAME")) to replace the common pattern of using is with a unique sentinel. These objects have informative representations and support proper type checking.
Statistical Sampling Profiler
The new profiling.sampling module offers statistical sampling profiling with minimal runtime impact, complementing the existing deterministic cProfile (still available as profiling.tracing).
Upgraded JIT
The JIT compiler, first introduced in Python 3.13, now delivers a geometric‑mean speed improvement of roughly 8%‑13% over standard CPython, depending on platform and workload. Gains stem from a new tracing frontend, register allocation, higher‑quality machine code, and optimizations such as eliminating ref‑count updates for certain object classes.
Clearer Error Messages
Error messages have become more precise. For missing attributes, the interpreter suggests possible correct names (e.g., "Did you mean 'xyz'?") and also checks for deleted attributes. When fuzzy name matching fails, it falls back to a list of common method names from other languages, suggesting .append() instead of the erroneous list.push().
Type System Improvements
TypedDictnow accepts closed (restrict runtime keys) and extra_items (declare additional keys with explicit types). The new TypeForm construct lets type expressions be evaluated to values, enabling uses such as typing.cast or isinstance in places where a type is treated as a value.
List‑Comprehension Unpacking
Flattening nested iterables can now be written with the star operator inside a comprehension, e.g., y = [*a for a in x]. The double‑star ** operator works for dictionary merging: y = {**d for d in dicts}. The same unpacking syntax can build generator expressions.
Garbage‑Collection Rollback
Python 3.14 introduced an incremental garbage collector that reduced pause times but increased overall memory usage for many users. Python 3.15 reverts to the classic generational collector, with the incremental collector slated to return only after further refinements.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
