Python 3.13.9 Released: Critical Regression Fix for inspect.getsourcelines

From Usahobs, the free encyclopedia of technology

Introduction

The Python development team has announced the release of Python 3.13.9, an expedited version aimed at addressing a specific regression found in the previous release, 3.13.8. This minor but important update ensures that developers relying on the inspect.getsourcelines function can once again retrieve source code lines correctly when decorators are followed by comments or empty lines. As with all Python releases, 3.13.9 is available for download from the official download page.

Python 3.13.9 Released: Critical Regression Fix for inspect.getsourcelines

What’s New in Python 3.13.9?

The sole change in this release is a targeted fix for a regression introduced in Python 3.13.8. The bug, tracked as gh-139783, affected the inspect.getsourcelines function. In certain scenarios, when a decorator in a Python source file was immediately followed by a comment or an empty line, the function would fail to correctly return the source lines for the decorated object. This could cause disruptions for tools and libraries that rely on introspection, such as debuggers, profilers, and testing frameworks.

Understanding the Regression

Python’s inspect module is a powerful tool for introspection, allowing developers to examine live objects, including their source code. The getsourcelines function specifically retrieves the lines of code that define a given function, class, or other objects. The regression meant that when a decorator looked like this:

@my_decorator
# This is a comment
def my_function():
    pass

…the function would wrongly raise an OSError or return incomplete or incorrect source lines. The fix ensures that empty lines and comments between the decorator and the decorated object are properly parsed, restoring the expected behavior.

Details of the Fix

The patch, crafted by the core development team, modifies the internal logic of getsourcelines to skip over comments and blank lines when tracing back from the object to its source definition. The correction is minimal and does not affect any other parts of the Python standard library. Because this is an expedited release, no additional features or improvements have been included beyond this one fix.

For users who have already upgraded to Python 3.13.8, the 3.13.9 release is highly recommended to avoid the source-line retrieval issue. Those still on Python 3.12 or earlier are unaffected by this specific regression, but may still benefit from the other improvements in the 3.13 series as documented in PEP 745.

How to Upgrade to Python 3.13.9

Installing or upgrading to Python 3.13.9 is straightforward:

  • Download the installer from the official release page for your operating system (Windows, macOS, Linux).
  • Using a package manager: On systems with pyenv or conda, run pyenv install 3.13.9 or conda install python=3.13.9.
  • Via the official Docker images: Pull the image python:3.13.9.

After upgrading, you can verify the version by running python --version in your terminal. The fix for inspect.getsourcelines will be automatically applied.

Acknowledgments and Community Support

This release was made possible by the dedication of countless volunteers and contributors. The Python Software Foundation (PSF) thanks everyone who reported the issue, submitted patches, and tested the fix. The expedited release team, consisting of Thomas Wouters, Ned Deily, Steve Dower, and Łukasz Langa, coordinated the swift turnaround.

The success of Python relies on community involvement. Whether you volunteer your time, contribute code, or make a financial contribution to the PSF, every effort helps. Consider supporting the foundation through donations or by participating in the CPython project on GitHub.

Conclusion

Python 3.13.9 is a focused, low-risk update that addresses a critical regression in the inspect module. All users of Python 3.13.8 are encouraged to upgrade as soon as possible to restore full introspection capabilities. For more details, refer to the 3.13 online documentation and the official release schedule. Enjoy the new release and happy coding!

Article last updated: 2025-04-10