Skip to content

Commit 9119852

Browse files
committed
Python: port py/super-not-enclosing-class
1 parent 92ee0aa commit 9119852

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

python/ql/src/Expressions/CallToSuperWrongClass.ql

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@
1313
*/
1414

1515
import python
16+
import semmle.python.dataflow.new.DataFlow
1617

17-
from CallNode call_to_super, string name
18+
from DataFlow::CallCfgNode call_to_super, string name
1819
where
19-
exists(GlobalVariable gv, ControlFlowNode cn |
20-
call_to_super = ClassValue::super_().getACall() and
21-
gv.getId() = "super" and
22-
cn = call_to_super.getArg(0) and
23-
name = call_to_super.getScope().getScope().(Class).getName() and
24-
exists(ClassValue other |
25-
cn.pointsTo(other) and
26-
not other.getScope().getName() = name
27-
)
20+
call_to_super.getFunction().getALocalSource().asExpr().(Name).getId() = "super" and
21+
name = call_to_super.getScope().getScope().(Class).getName() and
22+
exists(DataFlow::Node arg |
23+
arg = call_to_super.getArg(0) and
24+
not arg.getALocalSource().asExpr().(Name).getId() = name
2825
)
2926
select call_to_super.getNode(), "First argument to super() should be " + name + "."
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| test.py:10:9:10:27 | super() | First argument to super() should be NotMyDict. |
1+
| test.py:10:9:10:27 | ControlFlowNode for super() | First argument to super() should be NotMyDict. |

0 commit comments

Comments
 (0)