File tree Expand file tree Collapse file tree
python/ql/src/semmle/python Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import python
2+
3+ module MagicMethod {
4+ abstract class Potential extends ControlFlowNode {
5+ abstract string getMagicMethodName ( ) ;
6+ abstract ControlFlowNode getArg ( int n ) ;
7+ ControlFlowNode getSelf ( ) { result = this .getArg ( 1 ) }
8+ }
9+
10+ class Actual extends ControlFlowNode {
11+ Object resolvedMagicMethod ;
12+
13+ Actual ( ) {
14+ exists ( Potential pot |
15+ this .( Potential ) = pot and
16+ pot .getSelf ( ) .( ClassObject ) .lookupAttribute ( pot .getMagicMethodName ( ) ) = resolvedMagicMethod
17+ )
18+ }
19+ }
20+ }
21+
22+ class MagicBinOp extends MagicMethod:: Potential , BinaryExprNode {
23+ Operator operator ;
24+
25+ MagicBinOp ( ) { this .getOp ( ) = operator }
26+
27+ override string getMagicMethodName ( ) {
28+ result = operator .getSpecialMethodName ( )
29+ }
30+
31+ override ControlFlowNode getArg ( int n ) {
32+ n = 1 and result = this .getLeft ( )
33+ or
34+ n = 2 and result = this .getRight ( )
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments