Skip to content

[RFC] inspect: BlockFinder: handle nested parens with decorators #21425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
10 changes: 8 additions & 2 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ def __init__(self):
self.passline = False
self.indecorator = False
self.decoratorhasargs = False
self.nestedparens = 0
self.last = 1

def tokeneater(self, type, token, srowcol, erowcol, line):
Expand All @@ -941,10 +942,15 @@ def tokeneater(self, type, token, srowcol, erowcol, line):
elif token == "(":
if self.indecorator:
self.decoratorhasargs = True
self.nestedparens += 1
elif token == ")":
if self.indecorator:
self.indecorator = False
self.decoratorhasargs = False
self.nestedparens -= 1
if self.nestedparens == 0:
self.indecorator = False
self.decoratorhasargs = False
else:
assert self.nestedparens > 0, self.nestedparens
elif type == tokenize.NEWLINE:
self.passline = False # stop skipping when a NEWLINE is seen
self.last = srowcol[0]
Expand Down