Skip to content

Commit befe73d

Browse files
committed
Python: supress non-useful results (w/ tests) for iter str/seq query
Fixes github#3207
1 parent 94ccc16 commit befe73d

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

python/ql/src/Statements/IterableStringOrSequence.ql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313

1414
import python
15+
import semmle.python.filters.Tests
1516

1617
predicate has_string_type(Value v) {
1718
v.getClass() = ClassValue::str()
@@ -28,7 +29,10 @@ where
2829
iter.pointsTo(seq, seq_origin) and
2930
has_string_type(str) and
3031
seq.getClass().isIterable() and
31-
not has_string_type(seq)
32+
not has_string_type(seq) and
33+
// suppress occurrences from tests
34+
not seq_origin.getScope().getScope*() instanceof TestScope and
35+
not str_origin.getScope().getScope*() instanceof TestScope
3236
select loop,
3337
"Iteration over $@, of class " + seq.getClass().getName() + ", may also iterate over $@.",
3438
seq_origin, "sequence", str_origin, "string"
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
| 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 |
2-
| 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 |
3-
| 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 |

0 commit comments

Comments
 (0)