Python 3.13.9 Released: Critical Regression Fix for inspect.getsourcelines
By ⚡ min read
<h2>Introduction</h2>
<p>The Python development team has announced the release of <strong>Python 3.13.9</strong>, 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 <code>inspect.getsourcelines</code> 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 <a href="#download" id="download-link">download page</a>.</p><figure style="margin:20px 0"><img src="https://picsum.photos/seed/4247319753/800/450" alt="Python 3.13.9 Released: Critical Regression Fix for inspect.getsourcelines" style="width:100%;height:auto;border-radius:8px" loading="lazy"><figcaption style="font-size:12px;color:#666;margin-top:5px"></figcaption></figure>
<h2 id="whats-new">What’s New in Python 3.13.9?</h2>
<p>The sole change in this release is a targeted fix for a regression introduced in Python 3.13.8. The bug, tracked as <a href="https://github.com/python/cpython/issues/139783">gh-139783</a>, affected the <code>inspect.getsourcelines</code> 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.</p>
<h3>Understanding the Regression</h3>
<p>Python’s <code>inspect</code> module is a powerful tool for introspection, allowing developers to examine live objects, including their source code. The <code>getsourcelines</code> 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:</p>
<pre><code>@my_decorator
# This is a comment
def my_function():
pass</code></pre>
<p>…the function would wrongly raise an <code>OSError</code> 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.</p>
<h2 id="details">Details of the Fix</h2>
<p>The patch, crafted by the core development team, modifies the internal logic of <code>getsourcelines</code> 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 <em>expedited</em> release, no additional features or improvements have been included beyond this one fix.</p>
<p>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 <a href="https://peps.python.org/pep-0745/">PEP 745</a>.</p>
<h2 id="upgrade">How to Upgrade to Python 3.13.9</h2>
<p>Installing or upgrading to Python 3.13.9 is straightforward:</p>
<ul>
<li><strong>Download the installer</strong> from the <a href="https://www.python.org/downloads/release/python-3139/">official release page</a> for your operating system (Windows, macOS, Linux).</li>
<li><strong>Using a package manager</strong>: On systems with <code>pyenv</code> or <code>conda</code>, run <code>pyenv install 3.13.9</code> or <code>conda install python=3.13.9</code>.</li>
<li><strong>Via the official Docker images</strong>: Pull the image <code>python:3.13.9</code>.</li>
</ul>
<p>After upgrading, you can verify the version by running <code>python --version</code> in your terminal. The fix for <code>inspect.getsourcelines</code> will be automatically applied.</p>
<h2 id="acknowledgments">Acknowledgments and Community Support</h2>
<p>This release was made possible by the dedication of countless volunteers and contributors. The <strong>Python Software Foundation</strong> (PSF) thanks everyone who reported the issue, submitted patches, and tested the fix. The expedited release team, consisting of <strong>Thomas Wouters, Ned Deily, Steve Dower, and Łukasz Langa</strong>, coordinated the swift turnaround.</p>
<p>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 <a href="https://www.python.org/psf/donations/">donations</a> or by participating in the <a href="https://github.com/python/cpython">CPython project on GitHub</a>.</p>
<h2>Conclusion</h2>
<p>Python 3.13.9 is a focused, low-risk update that addresses a critical regression in the <code>inspect</code> 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 <a href="https://docs.python.org/3.13/">3.13 online documentation</a> and the official <a href="https://peps.python.org/pep-0745/">release schedule</a>. Enjoy the new release and happy coding!</p>
<p><small>Article last updated: 2025-04-10</small></p>