summaryrefslogtreecommitdiff
path: root/coverage/parser.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-11-10 21:53:06 -0500
committerNed Batchelder <ned@nedbatchelder.com>2021-11-10 21:53:06 -0500
commit0387bbaa5e9ab2ad834311249802695ebb0c34ca (patch)
tree81eba7ac0b1fe21c4ad3230efcc9a97fe920e606 /coverage/parser.py
parentd1d60a72cd60b2472d02cdbbcb487e31f25fe32a (diff)
downloadpython-coveragepy-git-0387bbaa5e9ab2ad834311249802695ebb0c34ca.tar.gz
fix: colons in decorators shouldn't stop an exclusion
Diffstat (limited to 'coverage/parser.py')
-rw-r--r--coverage/parser.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/coverage/parser.py b/coverage/parser.py
index ec788c06..b47fd12e 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -67,7 +67,7 @@ class PythonParser:
# The raw line numbers of excluded lines of code, as marked by pragmas.
self.raw_excluded = set()
- # The line numbers of class and function definitions.
+ # The line numbers of class definitions.
self.raw_classdefs = set()
# The line numbers of docstring lines.
@@ -120,6 +120,7 @@ class PythonParser:
first_line = None
empty = True
first_on_line = True
+ nesting = 0
tokgen = generate_tokens(self.text)
for toktype, ttext, (slineno, _), (elineno, _), ltext in tokgen:
@@ -139,7 +140,7 @@ class PythonParser:
# lines with the 'class' keyword.
self.raw_classdefs.add(slineno)
elif toktype == token.OP:
- if ttext == ':':
+ if ttext == ':' and nesting == 0:
should_exclude = (elineno in self.raw_excluded) or excluding_decorators
if not excluding and should_exclude:
# Start excluding a suite. We trigger off of the colon
@@ -155,6 +156,10 @@ class PythonParser:
excluding_decorators = True
if excluding_decorators:
self.raw_excluded.add(elineno)
+ elif ttext in "([{":
+ nesting += 1
+ elif ttext in ")]}":
+ nesting -= 1
elif toktype == token.STRING and prev_toktype == token.INDENT:
# Strings that are first on an indented line are docstrings.
# (a trick from trace.py in the stdlib.) This works for