|
12 | 12 | */ |
13 | 13 |
|
14 | 14 | import python |
15 | | -private import LegacyPointsTo |
16 | 15 | import Variables.Definition |
17 | 16 | import semmle.python.ApiGraphs |
| 17 | +private import semmle.python.dataflow.new.internal.ImportResolution |
| 18 | +private import semmle.python.dataflow.new.internal.DataFlowDispatch |
18 | 19 |
|
19 | 20 | private predicate is_pytest_fixture(Import imp, Variable name) { |
20 | 21 | exists(Alias a, API::Node pytest_fixture, API::Node decorator | |
@@ -95,7 +96,7 @@ private string typehint_annotation_in_module(Module module_scope) { |
95 | 96 | or |
96 | 97 | annotation = any(FunctionExpr f).getReturns().getASubExpression*() |
97 | 98 | | |
98 | | - annotation.(ExprWithPointsTo).pointsTo(Value::forString(result)) and |
| 99 | + annotation.getText() = result and |
99 | 100 | annotation.getEnclosingModule() = module_scope |
100 | 101 | ) |
101 | 102 | } |
@@ -143,9 +144,8 @@ predicate unused_import(Import imp, Variable name) { |
143 | 144 | not imported_module_used_in_doctest(imp) and |
144 | 145 | not imported_alias_used_in_typehint(imp, name) and |
145 | 146 | not is_pytest_fixture(imp, name) and |
146 | | - // Only consider import statements that actually point-to something (possibly an unknown module). |
147 | | - // If this is not the case, it's likely that the import statement never gets executed. |
148 | | - imp.getAName().getValue().(ExprWithPointsTo).pointsTo(_) |
| 147 | + // Only consider import statements in reachable code. |
| 148 | + Reachability::likelyReachable(imp.getAName().getValue().getAFlowNode().getBasicBlock()) |
149 | 149 | } |
150 | 150 |
|
151 | 151 | from Stmt s, Variable name |
|
0 commit comments