[3.14] gh-139783: Fix inspect.getsourcelines() for the case when a decorator is followed by a comment or an empty line (GH-139836) (GH-139889)
Some checks are pending
Tests / Windows MSI (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if the ABI has changed (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Android (aarch64) (push) Blocked by required conditions
Tests / Android (x86_64) (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run

(cherry picked from commit f4104f5d74)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-10-10 10:18:32 +02:00 committed by GitHub
parent 5d34830f4d
commit 08738ce521
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 1 deletions

View file

@ -1065,7 +1065,9 @@ class BlockFinder:
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 == "@":

View file

@ -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

View file

@ -1223,6 +1223,10 @@ class TestBuggyCases(GetSourceBase):
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):

View file

@ -0,0 +1,2 @@
Fix :func:`inspect.getsourcelines` for the case when a decorator is followed
by a comment or an empty line.