File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,10 @@ development at the same time, such as 4.5.x and 5.0.
20
20
Unreleased
21
21
----------
22
22
23
- Nothing yet.
23
+ - Fixed a mis-measurement of a strange use of wildcard alternatives in
24
+ match/case statements, closing `issue 1421 `_.
25
+
26
+ .. _issue 1421 : https://github.com/nedbat/coveragepy/issues/1421
24
27
25
28
26
29
.. _changes_6-6-0b1 :
Original file line number Diff line number Diff line change @@ -1041,7 +1041,10 @@ def _handle__Match(self, node):
1041
1041
had_wildcard = False
1042
1042
for case in node .cases :
1043
1043
case_start = self .line_for_node (case .pattern )
1044
- if isinstance (case .pattern , ast .MatchAs ):
1044
+ pattern = case .pattern
1045
+ while isinstance (pattern , ast .MatchOr ):
1046
+ pattern = pattern .patterns [- 1 ]
1047
+ if isinstance (pattern , ast .MatchAs ):
1045
1048
had_wildcard = True
1046
1049
self .add_arc (last_start , case_start , "the pattern on line {lineno} always matched" )
1047
1050
from_start = ArcStart (case_start , cause = "the pattern on line {lineno} never matched" )
Original file line number Diff line number Diff line change @@ -1362,6 +1362,19 @@ def test_match_case_without_wildcard(self):
1362
1362
)
1363
1363
assert self .stdout () == "None\n no go\n go: n\n "
1364
1364
1365
+ def test_absurd_wildcard (self ):
1366
+ # https://github.com/nedbat/coveragepy/issues/1421
1367
+ self .check_coverage ("""\
1368
+ def absurd(x):
1369
+ match x:
1370
+ case (3 | 99 | (999 | _)):
1371
+ print("default")
1372
+ absurd(5)
1373
+ """ ,
1374
+ arcz = ".1 15 5. .2 23 34 4." ,
1375
+ )
1376
+ assert self .stdout () == "default\n "
1377
+
1365
1378
1366
1379
class OptimizedIfTest (CoverageTest ):
1367
1380
"""Tests of if statements being optimized away."""
You can’t perform that action at this time.
0 commit comments