Skip to content

Commit 4a5aae0

Browse files
committed
Python: autoformat (4 spaces) NonCls.ql NonSelf.ql
1 parent 457794e commit 4a5aae0

File tree

2 files changed

+42
-39
lines changed

2 files changed

+42
-39
lines changed

python/ql/src/Functions/NonCls.ql

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import python
1616

1717
predicate first_arg_cls(Function f) {
1818
exists(string argname | argname = f.getArgName(0) |
19-
argname = "cls" or
19+
argname = "cls"
20+
or
2021
/* Not PEP8, but relatively common */
2122
argname = "mcls"
2223
)
@@ -27,21 +28,21 @@ predicate is_type_method(Function f) {
2728
}
2829

2930
predicate classmethod_decorators_only(Function f) {
30-
forall(Expr decorator |
31-
decorator = f.getADecorator() |
32-
decorator.(Name).getId() = "classmethod")
31+
forall(Expr decorator | decorator = f.getADecorator() | decorator.(Name).getId() = "classmethod")
3332
}
3433

3534
from Function f, string message
36-
where (f.getADecorator().(Name).getId() = "classmethod" or is_type_method(f)) and
37-
not first_arg_cls(f) and classmethod_decorators_only(f) and
38-
not f.getName() = "__new__" and
39-
(
40-
if exists(f.getArgName(0)) then
41-
message = "Class methods or methods of a type deriving from type should have 'cls', rather than '" +
42-
f.getArgName(0) + "', as their first parameter."
43-
else
44-
message = "Class methods or methods of a type deriving from type should have 'cls' as their first parameter."
45-
)
46-
35+
where
36+
(f.getADecorator().(Name).getId() = "classmethod" or is_type_method(f)) and
37+
not first_arg_cls(f) and
38+
classmethod_decorators_only(f) and
39+
not f.getName() = "__new__" and
40+
(
41+
if exists(f.getArgName(0))
42+
then
43+
message = "Class methods or methods of a type deriving from type should have 'cls', rather than '"
44+
+ f.getArgName(0) + "', as their first parameter."
45+
else
46+
message = "Class methods or methods of a type deriving from type should have 'cls' as their first parameter."
47+
)
4748
select f, message

python/ql/src/Functions/NonSelf.ql

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,34 @@ predicate is_type_method(FunctionValue fv) {
2121
}
2222

2323
predicate used_in_defining_scope(FunctionValue fv) {
24-
exists(Call c |
25-
c.getScope() = fv.getScope().getScope() and c.getFunc().pointsTo(fv)
26-
)
24+
exists(Call c | c.getScope() = fv.getScope().getScope() and c.getFunc().pointsTo(fv))
2725
}
2826

2927
from Function f, FunctionValue fv, string message
3028
where
31-
exists(ClassValue cls, string name |
32-
cls.declaredAttribute(name) = fv and cls.isNewStyle() and
33-
not name = "__new__" and
34-
not name = "__metaclass__" and
35-
/* declared in scope */
36-
f.getScope() = cls.getScope()
37-
) and
38-
not f.getArgName(0) = "self" and
39-
not is_type_method(fv) and
40-
fv.getScope() = f and
41-
not f.getName() = "lambda" and
42-
not used_in_defining_scope(fv) and
43-
(
44-
if exists(f.getArgName(0)) then
45-
message = "Normal methods should have 'self', rather than '" + f.getArgName(0) + "', as their first parameter."
46-
else
47-
message = "Normal methods should have at least one parameter (the first of which should be 'self')." and
48-
not f.hasVarArg()
49-
) and
50-
not fv instanceof ZopeInterfaceMethodValue
51-
29+
exists(ClassValue cls, string name |
30+
cls.declaredAttribute(name) = fv and
31+
cls.isNewStyle() and
32+
not name = "__new__" and
33+
not name = "__metaclass__" and
34+
/* declared in scope */
35+
f.getScope() = cls.getScope()
36+
) and
37+
not f.getArgName(0) = "self" and
38+
not is_type_method(fv) and
39+
fv.getScope() = f and
40+
not f.getName() = "lambda" and
41+
not used_in_defining_scope(fv) and
42+
(
43+
(
44+
if exists(f.getArgName(0))
45+
then
46+
message = "Normal methods should have 'self', rather than '" + f.getArgName(0) +
47+
"', as their first parameter."
48+
else
49+
message = "Normal methods should have at least one parameter (the first of which should be 'self')."
50+
) and
51+
not f.hasVarArg()
52+
) and
53+
not fv instanceof ZopeInterfaceMethodValue
5254
select f, message

0 commit comments

Comments
 (0)