Skip to content

Commit 1e2f41a

Browse files
committed
fix: excluding TYPE_CHECKING should have been the line not the branch
1 parent 2134e57 commit 1e2f41a

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ upgrading your version of coverage.py.
2323
Unreleased
2424
----------
2525

26+
- Fix: the exclusion for ``if TYPE_CHECKING:`` was wrong: it marked the branch
27+
as partial, but it should have been a line exclusion so the entire clause
28+
would be excluded.
29+
2630
- Fix: changed where .pth files are written for ``patch = subprocess``, closing
2731
`issue 2006`_.
2832

coverage/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def getregexlist(self, section: str, option: str) -> list[str]:
147147
DEFAULT_EXCLUDE = [
148148
r"#\s*(pragma|PRAGMA)[:\s]?\s*(no|NO)\s*(cover|COVER)",
149149
r"^\s*(((async )?def .*?)?\)(\s*->.*?)?:\s*)?\.\.\.\s*(#|$)",
150+
r"if (typing\.)?TYPE_CHECKING:",
150151
]
151152

152153
# The default partial branch regexes, to be modified by the user.
@@ -160,7 +161,6 @@ def getregexlist(self, section: str, option: str) -> list[str]:
160161
DEFAULT_PARTIAL_ALWAYS = [
161162
"while (True|1|False|0):",
162163
"if (True|1|False|0):",
163-
r"if (typing\.)?TYPE_CHECKING:",
164164
]
165165

166166

tests/test_arcs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,8 +2164,8 @@ def test_default(self) -> None:
21642164
if typing.TYPE_CHECKING: # only for mypy
21652165
g = 12
21662166
""",
2167-
lines=[1,2,3,4,5,6,7,8,9,10,11,12],
2168-
missing="12",
2167+
lines=[1,2,3,4,5,6,7,8,9,10],
2168+
missing="",
21692169
branchz="23 24 56 57 89 8A BC B.",
21702170
branchz_missing="",
21712171
)

0 commit comments

Comments
 (0)