mirror of
https://github.com/python/cpython.git
synced 2025-10-19 07:53:46 +00:00
gh-139783: Fix inspect.getsourcelines() for the case when a decorator is followed by a comment or an empty line (GH-139836)
This commit is contained in:
parent
e31c22dbf9
commit
f4104f5d74
4 changed files with 21 additions and 1 deletions
|
@ -1065,7 +1065,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 == "@":
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1223,6 +1223,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):
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Fix :func:`inspect.getsourcelines` for the case when a decorator is followed
|
||||
by a comment or an empty line.
|
Loading…
Add table
Add a link
Reference in a new issue