Skip to content

Python: tests with false positives around match #16764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
| 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. |
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,12 @@ def indirectly_returning_different_tuple_sizes(x):

def mismatched_multi_assign(x):
a,b = returning_different_tuple_sizes(x)
return a,b
return a,b


def ok_match(x): # FP
match x:
case True | 'true':
return 0
case _:
raise ValueError(x)
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
| 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:144:13:144:16 | Pass | This statement is unreachable. |
| test.py:147:9:148:16 | Case | This statement is unreachable. |
9 changes: 9 additions & 0 deletions python/ql/test/query-tests/Statements/unreachable/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,12 @@ def unreachable_catch_all_raise(x):
pass
else:
raise ValueError(x)

def ok_match(x):
match x:
case False:
pass # FP
case True:
pass
case _: # FP
pass
Loading