mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Exclude some decorators
This commit is contained in:
@@ -43,6 +43,15 @@ private predicate usedInInit(Function f, Class c) {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `f` has no arguments, and also has a decorator.
|
||||
* We assume that the decorator affect the method in such a way that a `self` parameter is unneeded.
|
||||
*/
|
||||
private predicate noArgsWithDecorator(Function f) {
|
||||
not exists(f.getAnArg()) and
|
||||
exists(f.getADecorator())
|
||||
}
|
||||
|
||||
/** Holds if the first parameter of `f` should be named `self`. */
|
||||
predicate shouldBeSelf(Function f, Class c) {
|
||||
methodOfClass(f, c) and
|
||||
@@ -50,7 +59,8 @@ predicate shouldBeSelf(Function f, Class c) {
|
||||
not isClassmethod(f) and
|
||||
not isMetaclass(c) and
|
||||
not isZopeInterface(c) and
|
||||
not usedInInit(f, c)
|
||||
not usedInInit(f, c) and
|
||||
not noArgsWithDecorator(f)
|
||||
}
|
||||
|
||||
/** Holds if the first parameter of `f` should be named `cls`. */
|
||||
|
||||
@@ -120,7 +120,15 @@ class Z(zope.interface.Interface):
|
||||
|
||||
Z().meth(0)
|
||||
|
||||
def weird_decorator(f):
|
||||
def g(self):
|
||||
return f()
|
||||
return g
|
||||
|
||||
class B:
|
||||
@weird_decorator
|
||||
def f(): # allow no-arg functions with a decorator
|
||||
pass
|
||||
|
||||
# The `__init_subclass__` (introduced in Python 3.6)
|
||||
# and `__class_getitem__` (introduced in Python 3.7) methods are methods
|
||||
|
||||
Reference in New Issue
Block a user