Who we are

Contacts

1815 W 14th St, Houston, TX 77008

281-817-6190

Development Python Technology

Python First Look: June 2024 Top Features and Improvements

Detailing Python 3.12.4 Release Updates

Introduction

With the release of Python 3.12.4 in June 2024, the Python community welcomes an array of exciting new features and critical fixes. This version is packed with enhancements that improve security, performance, and usability, solidifying Python’s reputation as a powerful and versatile programming language. Whether you’re a seasoned developer or just starting your coding journey, staying updated with the latest Python versions is essential to leverage the most advanced tools and best practices.

In this post, we’ll take a first look at the most noteworthy features and improvements in Python 3.12.4. From significant security updates to core functionality enhancements and library optimizations, there’s a lot to explore. Let’s dive in and see what makes this release a must-have for Python enthusiasts.

Security Enhancements

os.mkdir() on Windows

One of the key security updates in Python 3.12.4 is the enhancement to os.mkdir() on Windows. This function now accepts a mode of 0o700, which restricts the new directory to the current user. This change addresses CVE-2024-4030, a security vulnerability affecting tempfile.mkdtemp() when the base temporary directory had more permissive settings than intended.

Update to Bundled libexpat

Python 3.12.4 includes an update to the bundled libexpat library, bringing it to version 2.6.2. This update ensures that Python’s XML parsing capabilities remain secure and robust, benefiting applications that rely on XML data.

Improved Hashlib Support

Another significant improvement is the enhanced detection of BLAKE2, SHA3, Shake, and truncated SHA512 support in the OpenSSL-ish libcrypto library. This update allows the hashlib module to be used more effectively with libraries that may not support every algorithm offered by the upstream OpenSSL. This change ensures that developers have access to a wider range of cryptographic functions, enhancing the security and flexibility of Python applications.

These security enhancements highlight Python’s ongoing commitment to providing a secure and reliable environment for developers. Upgrading to Python 3.12.4 ensures that your applications benefit from the latest protections and cryptographic capabilities.

Core and Builtins Improvements

Annotation Scopes Fix

Python 3.12.4 addresses an issue with the execution of annotation scopes within classes when the globals parameter is set to a non-dict object. This fix ensures that type annotations and other scoped variables within classes function correctly, enhancing the reliability of code that relies on advanced type hints and annotations.

os.path.normpath() Speed Up

The os.path.normpath() function has been optimized for better performance with a direct C call. This change speeds up the normalization of path names, making file system operations more efficient, especially in applications that heavily manipulate file paths.

Generic Classes Bug Fixes

Several bugs related to generic classes have been fixed in this release. One issue involved unexpected name mangling in the bases of generic classes, and another where names appearing after a generic class were incorrectly mangled as if they were within the generic class. These fixes improve the accuracy and predictability of name resolution in generic class definitions.

os.path.isfile() on Windows

A bug affecting os.path.isfile() on Windows, where the function incorrectly handled pipes, has been resolved. This ensures that file type checks on Windows systems are more accurate and consistent.

Subinterpreter Bug Fix

Python 3.12.4 fixes a bug where non-builtin modules built with argument clinic were crashing if used in a subinterpreter before the main interpreter. The objects causing this problem by leaking between interpreters have been corrected, improving the stability of applications that use multiple interpreters.

These improvements to Python’s core and built-in functionalities enhance the language’s robustness and performance. Developers can expect more reliable behavior and better performance, making their codebases more efficient and easier to maintain.

Library Updates

Logging Configuration

In Python 3.12.4, a regression affecting logging configuration with multiprocessing queue types has been fixed. This ensures that logging setups involving multiprocessing can now be configured smoothly, improving the reliability of logging in complex applications.

shutil.rmtree() Fixes

The shutil.rmtree() function, which is used for removing directory trees, has seen significant improvements. A longstanding issue where a RecursionError was raised on deep directory trees has been addressed. The function is now more robust and can handle deeply nested directory structures without errors.

os.fwalk() Update

Similar to shutil.rmtree(), the os.fwalk() function, used for walking directory trees, has been updated to an iterative implementation. This change prevents RecursionError in deep directory trees, making os.fwalk() more reliable for extensive file system operations.

asyncio.ProactorEventLoop

The asyncio.ProactorEventLoop now raises a ValueError if the given socket is not in non-blocking mode. This change aligns the behavior with other loop implementations and ensures that asyncio operations are consistent and predictable.

High DPI Fix in turtledemo

Python 3.12.4 addresses an issue with high DPI settings that caused the turtledemo windows to appear blurry. This fix ensures that turtle graphics examples look sharp and clear on high-resolution displays, enhancing the user experience.

Email Module Fixes

The email module has received several important fixes. An AttributeError that occurred when re-folding a long address list has been resolved. Additionally, incorrect encoding of the address separator in address lists has been fixed, ensuring that email handling is more robust and error-free.

unittest.mock.create_autospec()

The unittest.mock.create_autospec() function has been updated to correctly configure parent mocks with keyword arguments. This improvement enhances the accuracy and reliability of mock objects in unit tests, making it easier to write and maintain test suites.

These library updates in Python 3.12.4 ensure that key functionalities are more reliable, efficient, and user-friendly. By addressing longstanding issues and introducing thoughtful enhancements, this release provides a more robust foundation for developing Python applications.

Performance and Optimization

Tokenize Module Performance

Python 3.12.4 brings a significant performance enhancement to the tokenize module. By caching the line token attribute and calculating the column offset more efficiently, this update speeds up tokenization processes, which is particularly beneficial for applications that perform extensive source code analysis or manipulation.

Decimal Module Optimization

The Python implementation of the decimal module has been optimized to handle power cases more efficiently. Previously, the module could appear to hang when dealing with relatively small power cases (like 2**117) if the context precision was set to a very high value. The new method to check for exactly representable results avoids computing 10**precision, which could be computationally expensive. This optimization not only enhances performance but also improves the module’s reliability in high-precision calculations.

These performance improvements make Python 3.12.4 faster and more efficient, ensuring that your applications run smoothly even when performing complex computations or handling large datasets. Upgrading to this version can lead to noticeable improvements in the speed and responsiveness of your Python programs.

Documentation and Tests

Updated Sphinx Version Requirement

The documentation for Python 3.12.4 now requires a minimum Sphinx version of 6.2.1. Sphinx is the tool used for generating Python’s official documentation, and this update ensures that the documentation remains modern and well-maintained, taking advantage of the latest features and improvements in Sphinx.

Bug Reporting Transition

Python’s bug reporting system has transitioned from bugs.python.org to GitHub. This change streamlines the process of reporting and tracking bugs, making it easier for the community to contribute to Python’s development. All documentation files and configuration outputs have been updated to reflect this new location for reporting bugs.

regrtest Test Runner Enhancement

The regrtest test runner, used for running Python’s regression tests, has been enhanced with XML support for the refleak checker (the -R option). This improvement makes it easier to integrate Python’s test results with continuous integration systems and other tools that consume XML test reports, providing better insights into test outcomes and potential issues.

These updates in documentation and testing demonstrate Python’s commitment to maintainability and community involvement. By adopting the latest tools and practices, Python ensures that both its users and contributors have a smooth and efficient experience.

Platform-Specific Changes

Windows Enhancements

Unicode Support for _winapi.CreateNamedPipe Python 3.12.4 brings improved Unicode support to _winapi.CreateNamedPipe, enhancing the ability to handle Unicode characters in named pipes. This change also includes fixes to audit events, ensuring better security and usability.

Improved Shebang Handling by py.exe The py.exe launcher on Windows now correctly interprets shebang lines such as /usr/bin/env python3.12. Previously, these were mistakenly interpreted as python3.exe instead of python3.12.exe. This improvement ensures that scripts run with the intended version of Python, enhancing compatibility and reducing potential errors.

Launcher Update Fixes Python 3.12.4 addresses issues with the launcher updates not being installed correctly. This fix ensures that future updates are applied seamlessly, maintaining the stability and security of the Python environment on Windows.

Virtual Environment Creation Warnings The warning displayed during virtual environment creation when the requested and created paths differ only by a short (8.3 style) name is now suppressed. This change helps reduce unnecessary warnings and clarifies the virtual environment creation process. Warnings will still be shown if a junction or symlink in the path causes the virtual environment to be created in a different location than originally requested.

macOS Enhancements

SQLite and Tcl/Tk Updates The macOS installer for Python 3.12.4 has been updated to include SQLite 3.45.3 and Tcl/Tk 8.6.14. These updates ensure that Python’s database and GUI capabilities remain current and reliable, benefiting applications that rely on these components.

These platform-specific changes in Python 3.12.4 highlight the attention to detail and commitment to providing a consistent and reliable experience across different operating systems. Whether you are developing on Windows or macOS, upgrading to Python 3.12.4 brings significant improvements to the development environment.

IDLE and C API Enhancements

IDLE Improvements

Python 3.12.4 brings a notable improvement to IDLE, the Integrated Development and Learning Environment. One key enhancement is the use of user-selected color themes for the Help => IDLE Doc. This change allows developers to maintain a consistent look and feel across the IDLE interface, improving the overall user experience and making the documentation easier to read and navigate.

C API Enhancements

Thread State Management Fixes The latest Python release includes a critical fix for a crash issue related to thread states created by PyGILState_Ensure(). This problem occurred when a destructor, called during PyThreadState_Clear(), re-entered PyGILState_Ensure() and PyGILState_Release(). By addressing this issue, Python 3.12.4 ensures more stable and reliable thread management, particularly in multi-threaded applications or those using thread-local variables.

datetime.fromisoformat() Validation Python 3.12.4 improves the validation logic in the C implementation of datetime.fromisoformat(). This enhancement ensures better handling of invalid year values, making the function more robust and less prone to errors. This change, contributed by Vlad Efanov, enhances the reliability of date and time parsing in Python applications.

These enhancements to IDLE and the C API in Python 3.12.4 demonstrate a continued focus on usability and stability. By refining the development environment and improving critical APIs, Python maintains its position as a top choice for developers seeking a reliable and user-friendly programming language.

Conclusion

Python 3.12.4 is a testament to the ongoing efforts of the Python community to enhance the language’s security, performance, and usability. This release introduces vital security improvements, such as better directory permissions on Windows and updated cryptographic support, ensuring that Python remains a secure choice for developers. Core and built-in enhancements, alongside library updates, provide significant performance boosts and bug fixes, making development smoother and more efficient.

The refinements in IDLE and the C API further improve the development experience, highlighting Python’s commitment to stability and usability. These enhancements collectively ensure that Python 3.12.4 is not just an incremental update but a substantial step forward in the evolution of the language.

Upgrading to Python 3.12.4 allows you to leverage these new features and improvements, keeping your development environment up-to-date and robust. Stay tuned for more updates and continue exploring the endless possibilities Python offers. Happy coding!