@@ -14,6 +14,8 @@ private predicate isMetaclass(Class c) {
1414/** Holds if `f` is a class method. */
1515private predicate isClassMethod ( Function f ) {
1616 f .getADecorator ( ) = API:: builtin ( "classmethod" ) .asSource ( ) .asExpr ( )
17+ or
18+ f .getName ( ) in [ "__new__" , "__init_subclass__" , "__metaclass__" , "__class_getitem__" ]
1719}
1820
1921/** Holds if `f` is a static method. */
@@ -37,8 +39,7 @@ predicate shouldBeSelf(Function f, Class c) {
3739 methodOfClass ( f , c ) and
3840 not isStaticMethod ( f ) and
3941 not isClassMethod ( f ) and
40- not f .getName ( ) in [ "__new__" , "__init_subclass__" , "__metaclass__" , "__class_getitem__" ] and
41- isMetaclass ( c ) and
42+ not isMetaclass ( c ) and
4243 not isZopeInterface ( c )
4344}
4445
@@ -47,9 +48,9 @@ predicate shouldBeCls(Function f, Class c) {
4748 methodOfClass ( f , c ) and
4849 not isStaticMethod ( f ) and
4950 (
50- isClassMethod ( f )
51+ isClassMethod ( f ) and not isMetaclass ( c )
5152 or
52- f . getName ( ) in [ "__new__" , "__init_subclass__" , "__metaclass__" , "__class_getitem__" ]
53+ isMetaclass ( c ) and not isClassMethod ( f )
5354 )
5455}
5556
@@ -68,12 +69,12 @@ predicate firstArgNamedCls(Function f) {
6869
6970/** Holds if the first parameter of `f` should be named `self`, but isn't. */
7071predicate firstArgShouldBeNamedSelfAndIsnt ( Function f ) {
71- exists ( Class c | shouldBeSelf ( f , c ) ) and
72+ shouldBeSelf ( f , _ ) and
7273 not firstArgNamedSelf ( f )
7374}
7475
7576/** Holds if the first parameter of `f` should be named `cls`, but isn't. */
7677predicate firstArgShouldBeNamedClsAndIsnt ( Function f ) {
77- exists ( Class c | shouldBeCls ( f , c ) ) and
78+ shouldBeCls ( f , _ ) and
7879 not firstArgNamedCls ( f )
7980}
0 commit comments