Geir Arne Hjelle and Christopher Trudeau discuss the new features of Python 3.12, including better error messaging, more intuitive f-strings, subinterpreters, the Linux perf profiler, improved typing syntax, and more. They provide advice on incorporating the updates into your projects and discuss when to start running Python 3.12.
Python 3.12 introduces better error messaging, making it easier to identify and fix errors.
The syntax for f-strings in Python 3.12 is simplified, improving their readability and flexibility.
Python 3.12 includes optimizations and type enhancements to make Python faster, more efficient, and provide a better typing experience for developers.
Deep dives
Improved Error Messaging
Python 3.12 introduces better error messaging, including improved syntax error messages and more informative tracebacks. Error messages related to imports and class instance attributes have also been enhanced, making it easier to identify and fix errors.
Simplified F-Strings
Python 3.12 simplifies the syntax for f-strings, making them more intuitive and consistent. The new syntax eliminates the need for nested quotes inside brace expressions, allows the use of backslashes, enables nesting of f-strings, and even permits comments within the expressions. These changes improve the readability and flexibility of working with f-strings.
Optimizations and Type Enhancements
Python 3.12 includes various optimizations and type enhancements. These optimizations involve improved specialized adaptive interpreters, inlining of comprehensions for faster execution, support for sub-interpreters to enhance concurrency, and new syntax for type variables, making them easier to use and understand. These updates aim to make Python faster, more efficient, and provide a better typing experience for developers.
Python 3.12 brings improvements to language maturity and performance profiling with Linux perf
Python 3.12 introduces features that highlight the language's maturity and address the limitations faced by large-scale software. The update includes improved error messages, better support for F-strings, enhanced performance profiling with Linux perf, and the addition of sub-interpreters for improved isolation. These updates contribute to optimizing code execution and providing a more efficient development experience.
New features in Python 3.12: Immortal objects and enhanced calendar module
Python 3.12 introduces the concept of immortal objects, which are a subset of immutable objects that can last for the lifetime of the interpreter. By optimizing metadata and memory usage, immortal objects improve startup times and reduce memory overhead. Additionally, the calendar module receives updates, introducing constants for weekdays and months, making it easier to work with dates and calendars within Python programming.
Python 3.12 is here! Our regular guests, Geir Arne Hjelle and Christopher Trudeau, return to discuss the new version. Geir Arne coordinated a series of preview articles with several members of the Real Python team this year, and his showcase tutorial, “Python 3.12: Cool New Features for You to Try,” came out on October 2. Christopher’s video course was posted the next day, covering the topics from the article with visual examples of Python 3.12 in action.
Geir Arne and Christopher collaborated to create code examples of the new features. We discuss better error messaging, more intuitive f-strings, subinterpreters, the Linux perf profiler, improved typing syntax, and more.
We dig into the updates and offer advice on incorporating them into your projects. We also consider when you should start running Python 3.12.
In this video course, you’ll explore the new features that Python 3.12 brings to the table. These include improved f-strings, better error messages, changes to CPython internals, additions to static typing, and more.