Skip to content

Commit

Permalink
Merge pull request #18524 from github/redsun82/python-match-fps
Browse files Browse the repository at this point in the history
Python: add some more FP tests around match
  • Loading branch information
yoff authored Jan 17, 2025
2 parents aa0b955 + 4ab5650 commit 15a1831
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
| functions_test.py:18:1:18:11 | Function cr1 | Mixing implicit and explicit returns may indicate an error as implicit returns always return None. |
| functions_test.py:22:1:22:11 | Function cr2 | Mixing implicit and explicit returns may indicate an error as implicit returns always return None. |
| functions_test.py:336:1:336:16 | Function ok_match | Mixing implicit and explicit returns may indicate an error as implicit returns always return None. |
| functions_test.py:344:1:344:17 | Function ok_match2 | Mixing implicit and explicit returns may indicate an error as implicit returns always return None. |
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,11 @@ def ok_match(x): # FP
return 0
case _:
raise ValueError(x)


def ok_match2(x): # FP
match x:
case None:
return 0
case _:
return 1
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
| test.py:21:5:21:38 | For | This statement is unreachable. |
| test.py:28:9:28:21 | ExprStmt | This statement is unreachable. |
| test.py:84:5:84:21 | ExceptStmt | This statement is unreachable. |
| test.py:158:9:159:16 | Case | This statement is unreachable. |
| test.py:162:13:162:16 | Pass | This statement is unreachable. |
| test.py:167:13:167:16 | Pass | This statement is unreachable. |
23 changes: 22 additions & 1 deletion python/ql/test/query-tests/Statements/unreachable/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,29 @@ def unreachable_catch_all_raise(x):
def ok_match(x):
match x:
case False:
pass # FP
pass
case True:
pass
case _:
pass

match x:
case "true":
pass
case _:
pass
match x:
case 42:
pass
case _: # FP
pass
match x:
case None:
pass # FP
case _:
pass
match x:
case 0.0:
pass # FP
case _:
pass

0 comments on commit 15a1831

Please sign in to comment.