Skip to content

Commit fa76bf3

Browse files
Fix formatting and rewrite redundant exists
1 parent 526e235 commit fa76bf3

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

python/ql/src/Functions/MethodArgNames.qll

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ private predicate isMetaclass(Class c) {
1414
/** Holds if `f` is a class method. */
1515
private 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. */
7071
predicate 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. */
7677
predicate firstArgShouldBeNamedClsAndIsnt(Function f) {
77-
exists(Class c | shouldBeCls(f, c)) and
78+
shouldBeCls(f, _) and
7879
not firstArgNamedCls(f)
7980
}

python/ql/src/Functions/NonSelf.ql

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ from Function f, string message
2020
where
2121
firstArgShouldBeNamedSelfAndIsnt(f) and
2222
(
23-
(
24-
if exists(f.getArgName(0))
25-
then
26-
message =
27-
"Normal methods should have 'self', rather than '" + f.getArgName(0) +
28-
"', as their first parameter."
29-
else
30-
message =
31-
"Normal methods should have at least one parameter (the first of which should be 'self')."
32-
) and
33-
)
23+
if exists(f.getArgName(0))
24+
then
25+
message =
26+
"Normal methods should have 'self', rather than '" + f.getArgName(0) +
27+
"', as their first parameter."
28+
else
29+
message =
30+
"Normal methods should have at least one parameter (the first of which should be 'self')."
31+
)
3432
select f, message

0 commit comments

Comments
 (0)