Skip to content

Commit

Permalink
Backport gh-83035: handle decorator with nested parens in inspect.get…
Browse files Browse the repository at this point in the history
…source (#99654)

Summary: Backport the upstream fix from python/cpython#99654

Test Plan: existing tests

Reviewers: carljm, #cinder

Reviewed By: carljm

Differential Revision: https://phabricator.intern.facebook.com/D41824891
  • Loading branch information
itamaro authored and Service User committed Dec 8, 2022
1 parent 121487c commit 903f676
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
11 changes: 1 addition & 10 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,6 @@ def __init__(self):
self.started = False
self.passline = False
self.indecorator = False
self.decoratorparenlevel = 0
self.last = 1
self.body_col0 = None

Expand All @@ -1067,22 +1066,14 @@ def tokeneater(self, type, token, srowcol, erowcol, line):
self.islambda = True
self.started = True
self.passline = True # skip to the end of the line
elif token == "(":
if self.indecorator:
self.decoratorparenlevel += 1
elif token == ")":
if self.indecorator:
self.decoratorparenlevel -= 1
if not self.decoratorparenlevel:
self.indecorator = False
elif type == tokenize.NEWLINE:
self.passline = False # stop skipping when a NEWLINE is seen
self.last = srowcol[0]
if self.islambda: # lambdas always end at the first NEWLINE
raise EndOfBlock
# hitting a NEWLINE when in a decorator without args
# ends the decorator
if self.indecorator and not self.decoratorparenlevel:
if self.indecorator:
self.indecorator = False
elif self.passline:
pass
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :func:`inspect.getsource` handling of decorator calls with nested parentheses.

0 comments on commit 903f676

Please sign in to comment.