mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
Python: supress non-useful results (w/ tests) for iter str/seq query
Fixes https://github.com/Semmle/ql/issues/3207
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
import semmle.python.filters.Tests
|
||||
|
||||
predicate has_string_type(Value v) {
|
||||
v.getClass() = ClassValue::str()
|
||||
@@ -28,7 +29,10 @@ where
|
||||
iter.pointsTo(seq, seq_origin) and
|
||||
has_string_type(str) and
|
||||
seq.getClass().isIterable() and
|
||||
not has_string_type(seq)
|
||||
not has_string_type(seq) and
|
||||
// suppress occurrences from tests
|
||||
not seq_origin.getScope().getScope*() instanceof TestScope and
|
||||
not str_origin.getScope().getScope*() instanceof TestScope
|
||||
select loop,
|
||||
"Iteration over $@, of class " + seq.getClass().getName() + ", may also iterate over $@.",
|
||||
seq_origin, "sequence", str_origin, "string"
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
| statements_test.py:21:5:21:19 | For | Iteration over $@, of class list, may also iterate over $@. | statements_test.py:20:13:20:33 | ControlFlowNode for List | sequence | statements_test.py:18:13:18:26 | ControlFlowNode for Str | string |
|
||||
| supress_uses_from_tests.py:6:5:6:20 | For | Iteration over $@, of class list, may also iterate over $@. | supress_uses_from_tests.py:9:5:9:26 | ControlFlowNode for List | sequence | supress_uses_from_tests.py:19:17:19:27 | ControlFlowNode for Str | string |
|
||||
| supress_uses_from_tests.py:6:5:6:20 | For | Iteration over $@, of class list, may also iterate over $@. | supress_uses_from_tests.py:15:13:15:34 | ControlFlowNode for List | sequence | supress_uses_from_tests.py:19:17:19:27 | ControlFlowNode for Str | string |
|
||||
|
||||
Reference in New Issue
Block a user