Skip to content

Commit 530b795

Browse files
authored
Merge pull request github#11402 from yoff/python/port-super-not-enclosing-class
Python: port `py/super-not-enclosing-class`
2 parents 8a94cab + 77d98b2 commit 530b795

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

python/ql/src/Expressions/CallToSuperWrongClass.ql

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

1515
import python
16+
import semmle.python.dataflow.new.DataFlow
17+
import semmle.python.ApiGraphs
1618

17-
from CallNode call_to_super, string name
19+
from DataFlow::CallCfgNode call_to_super, string name
1820
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-
)
21+
call_to_super = API::builtin("super").getACall() and
22+
name = call_to_super.getScope().getScope().(Class).getName() and
23+
exists(DataFlow::Node arg |
24+
arg = call_to_super.getArg(0) and
25+
arg.getALocalSource().asExpr().(Name).getId() != name
2826
)
2927
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)