Skip to content

Commit

Permalink
fixup! gh-105013: Fix inspect.getsource with parenthesized multiline …
Browse files Browse the repository at this point in the history
…lambdas
  • Loading branch information
pablogsal committed May 27, 2023
1 parent ff9abff commit 649397d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,11 @@ def getblock(lines):
except SyntaxError as e:
if "unmatched ')" not in e.msg:
raise e from None
_, *_token_info = _token
try:
blockfinder.tokeneater(tokenize.NEWLINE, *_token_info)
except (EndOfBlock, IndentationError):
pass
return lines[:blockfinder.last]

def getsourcelines(object):
Expand Down
7 changes: 6 additions & 1 deletion Lib/test/inspect_fodder2.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,9 @@ def complex_decorated(foo=0, bar=lambda: 0):

# line 281
post_line_parenthesized_lambda = (lambda: ()
)
)

# line 285
nested_lambda = (
lambda right: [].map(
lambda length: ()))
4 changes: 4 additions & 0 deletions Lib/test/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,10 @@ def test_post_line_parenthesized_lambda(self):
# function.
self.assertSourceEqual(mod2.post_line_parenthesized_lambda, 282, 283)

def test_nested_lambda(self):
# Test inspect.getsource with a nested lambda function.
self.assertSourceEqual(mod2.nested_lambda, 287, 288)

def test_onelinefunc(self):
# Test inspect.getsource with a regular one-line function.
self.assertSourceEqual(mod2.onelinefunc, 37, 37)
Expand Down

0 comments on commit 649397d

Please sign in to comment.