From bc2c8d748cf059712e9d513e05ea13e13844150d Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Fri, 10 Oct 2025 23:26:36 +0200 Subject: [PATCH 1/2] [3.13] gh-139783: Fix inspect.getsourcelines() for the case when a decorator is followed by a comment or an empty line (GH-139836) (GH-139890) (cherry picked from commit f4104f5d74b99712253fceb39a4460ee3f7a281c) Co-authored-by: Serhiy Storchaka --- Lib/inspect.py | 4 +++- Lib/test/test_inspect/inspect_fodder2.py | 12 ++++++++++++ Lib/test/test_inspect/test_inspect.py | 4 ++++ .../2025-10-09-13-48-28.gh-issue-139783.__NUgo.rst | 2 ++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2025-10-09-13-48-28.gh-issue-139783.__NUgo.rst diff --git a/Lib/inspect.py b/Lib/inspect.py index c5653f693f1..5a814f97b5b 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1168,7 +1168,9 @@ def __init__(self): def tokeneater(self, type, token, srowcol, erowcol, line): if not self.started and not self.indecorator: - if type == tokenize.INDENT or token == "async": + if type in (tokenize.INDENT, tokenize.COMMENT, tokenize.NL): + pass + elif token == "async": pass # skip any decorators elif token == "@": diff --git a/Lib/test/test_inspect/inspect_fodder2.py b/Lib/test/test_inspect/inspect_fodder2.py index 1de283f672d..157e12167b5 100644 --- a/Lib/test/test_inspect/inspect_fodder2.py +++ b/Lib/test/test_inspect/inspect_fodder2.py @@ -388,4 +388,16 @@ def func383(): ) return ge385 +# line 391 +@decorator +# comment +def func394(): + return 395 + +# line 397 +@decorator + +def func400(): + return 401 + pass # end of file diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index 691c2ffd5cc..49996bba2ca 100644 --- a/Lib/test/test_inspect/test_inspect.py +++ b/Lib/test/test_inspect/test_inspect.py @@ -1221,6 +1221,10 @@ def test_generator_expression(self): self.assertSourceEqual(next(mod2.ge377), 377, 380) self.assertSourceEqual(next(mod2.func383()), 385, 388) + def test_comment_or_empty_line_after_decorator(self): + self.assertSourceEqual(mod2.func394, 392, 395) + self.assertSourceEqual(mod2.func400, 398, 401) + class TestNoEOL(GetSourceBase): def setUp(self): diff --git a/Misc/NEWS.d/next/Library/2025-10-09-13-48-28.gh-issue-139783.__NUgo.rst b/Misc/NEWS.d/next/Library/2025-10-09-13-48-28.gh-issue-139783.__NUgo.rst new file mode 100644 index 00000000000..336653e73bf --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-10-09-13-48-28.gh-issue-139783.__NUgo.rst @@ -0,0 +1,2 @@ +Fix :func:`inspect.getsourcelines` for the case when a decorator is followed +by a comment or an empty line. From 8183fa5e3f78ca6ab862de7fb8b14f3d929421e0 Mon Sep 17 00:00:00 2001 From: Thomas Wouters Date: Tue, 14 Oct 2025 15:52:15 +0200 Subject: [PATCH 2/2] Python 3.13.9 --- Include/patchlevel.h | 4 ++-- Lib/pydoc_data/topics.py | 2 +- Misc/NEWS.d/3.13.9.rst | 8 ++++++++ .../2025-10-09-13-48-28.gh-issue-139783.__NUgo.rst | 2 -- README.rst | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 Misc/NEWS.d/3.13.9.rst delete mode 100644 Misc/NEWS.d/next/Library/2025-10-09-13-48-28.gh-issue-139783.__NUgo.rst diff --git a/Include/patchlevel.h b/Include/patchlevel.h index 3f7feaf0b33..00f6ce1f55e 100644 --- a/Include/patchlevel.h +++ b/Include/patchlevel.h @@ -18,12 +18,12 @@ /*--start constants--*/ #define PY_MAJOR_VERSION 3 #define PY_MINOR_VERSION 13 -#define PY_MICRO_VERSION 8 +#define PY_MICRO_VERSION 9 #define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_FINAL #define PY_RELEASE_SERIAL 0 /* Version as a string */ -#define PY_VERSION "3.13.8" +#define PY_VERSION "3.13.9" /*--end constants--*/ /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2. diff --git a/Lib/pydoc_data/topics.py b/Lib/pydoc_data/topics.py index 80cdf0cd49b..2ab577ffe8e 100644 --- a/Lib/pydoc_data/topics.py +++ b/Lib/pydoc_data/topics.py @@ -1,4 +1,4 @@ -# Autogenerated by Sphinx on Tue Oct 7 14:01:47 2025 +# Autogenerated by Sphinx on Tue Oct 14 15:52:27 2025 # as part of the release process. topics = { diff --git a/Misc/NEWS.d/3.13.9.rst b/Misc/NEWS.d/3.13.9.rst new file mode 100644 index 00000000000..d1ed11729fc --- /dev/null +++ b/Misc/NEWS.d/3.13.9.rst @@ -0,0 +1,8 @@ +.. date: 2025-10-09-13-48-28 +.. gh-issue: 139783 +.. nonce: __NUgo +.. release date: 2025-10-14 +.. section: Library + +Fix :func:`inspect.getsourcelines` for the case when a decorator is followed +by a comment or an empty line. diff --git a/Misc/NEWS.d/next/Library/2025-10-09-13-48-28.gh-issue-139783.__NUgo.rst b/Misc/NEWS.d/next/Library/2025-10-09-13-48-28.gh-issue-139783.__NUgo.rst deleted file mode 100644 index 336653e73bf..00000000000 --- a/Misc/NEWS.d/next/Library/2025-10-09-13-48-28.gh-issue-139783.__NUgo.rst +++ /dev/null @@ -1,2 +0,0 @@ -Fix :func:`inspect.getsourcelines` for the case when a decorator is followed -by a comment or an empty line. diff --git a/README.rst b/README.rst index f45f1a94f24..61aabbd6e5a 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -This is Python version 3.13.8 +This is Python version 3.13.9 ============================= .. image:: https://github.com/python/cpython/workflows/Tests/badge.svg