diff --git a/Lib/inspect.py b/Lib/inspect.py index 887a3424057b6e..ed4764948ac081 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -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): @@ -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]