Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion 4 Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "@":
Expand Down
12 changes: 12 additions & 0 deletions 12 Lib/test/test_inspect/inspect_fodder2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions 4 Lib/test/test_inspect/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :func:`inspect.getsourcelines` for the case when a decorator is followed
by a comment or an empty line.
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.