Merge pull request #11402 from yoff/python/port-super-not-enclosing-class

Python: port `py/super-not-enclosing-class`
This commit is contained in:
Taus
2022-11-28 11:52:57 +01:00
committed by GitHub
2 changed files with 9 additions and 11 deletions

View File

@@ -13,17 +13,15 @@
*/
import python
import semmle.python.dataflow.new.DataFlow
import semmle.python.ApiGraphs
from CallNode call_to_super, string name
from DataFlow::CallCfgNode call_to_super, string name
where
exists(GlobalVariable gv, ControlFlowNode cn |
call_to_super = ClassValue::super_().getACall() and
gv.getId() = "super" and
cn = call_to_super.getArg(0) and
name = call_to_super.getScope().getScope().(Class).getName() and
exists(ClassValue other |
cn.pointsTo(other) and
not other.getScope().getName() = name
)
call_to_super = API::builtin("super").getACall() and
name = call_to_super.getScope().getScope().(Class).getName() and
exists(DataFlow::Node arg |
arg = call_to_super.getArg(0) and
arg.getALocalSource().asExpr().(Name).getId() != name
)
select call_to_super.getNode(), "First argument to super() should be " + name + "."

View File

@@ -1 +1 @@
| test.py:10:9:10:27 | super() | First argument to super() should be NotMyDict. |
| test.py:10:9:10:27 | ControlFlowNode for super() | First argument to super() should be NotMyDict. |