Skip to content

Commit 918c05c

Browse files
tausbnyoff
andcommitted
Python: Don't prune any MatchLiteralPatterns
Extends the mechanism introduced in #18030 to behave the same for _all_ `MatchLiteralPattern`s, not just the ones that happen to be the constant `True` or `False`. Co-authored-by: yoff <[email protected]>
1 parent 7476d9e commit 918c05c

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

python/extractor/semmle/python/passes/pruner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ def __init__(self):
203203
self.nodes = set()
204204

205205
def visit_MatchLiteralPattern(self, node):
206-
# MatchLiteralPatterns _look_ like boolean tests, but are not.
206+
# MatchLiteralPatterns _look_ like boolean tests in that they have both a true ("matched")
207+
# and false ("didn't match") successor, but are not.
207208
# Thus, without this check, we would interpret
208209
#
209210
# match x:
@@ -212,8 +213,7 @@ def visit_MatchLiteralPattern(self, node):
212213
#
213214
# (and similarly for True) as if it was a boolean test. This would cause the true edge
214215
# (leading to pass) to be pruned later on.
215-
if isinstance(node.literal, ast.Name) and node.literal.id in ('True', 'False'):
216-
self.nodes.add(node.literal)
216+
self.nodes.add(node.literal)
217217

218218
class NonlocalVisitor(ASTVisitor):
219219
def __init__(self):

python/ql/test/query-tests/Statements/unreachable/UnreachableCode.expected

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,3 @@
44
| test.py:21:5:21:38 | For | This statement is unreachable. |
55
| test.py:28:9:28:21 | ExprStmt | This statement is unreachable. |
66
| test.py:84:5:84:21 | ExceptStmt | This statement is unreachable. |
7-
| test.py:158:9:159:16 | Case | This statement is unreachable. |
8-
| test.py:162:13:162:16 | Pass | This statement is unreachable. |
9-
| test.py:167:13:167:16 | Pass | This statement is unreachable. |

0 commit comments

Comments
 (0)