Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 546405a

Browse files
committed
Python: Add more tests for cls/self argument names
1 parent 5271d6a commit 546405a

3 files changed

Lines changed: 25 additions & 8 deletions

File tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
| argument_names.py:17:5:17:24 | Function n_cmethod | Class methods or methods of a type deriving from type should have 'cls', rather than 'self', as their first argument. |
2-
| argument_names.py:32:5:32:20 | Function c_method | Class methods or methods of a type deriving from type should have 'cls', rather than 'y', as their first argument. |
2+
| argument_names.py:22:5:22:21 | Function n_cmethod2 | Class methods or methods of a type deriving from type should have 'cls' as their first argument. |
3+
| argument_names.py:37:5:37:20 | Function c_method | Class methods or methods of a type deriving from type should have 'cls', rather than 'y', as their first argument. |
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
| argument_names.py:45:5:45:20 | Function __init__ | Normal methods should have 'self', rather than 'x', as their first parameter. |
2-
| argument_names.py:48:5:48:20 | Function s_method | Normal methods should have 'self', rather than 'y', as their first parameter. |
1+
| argument_names.py:50:5:50:20 | Function __init__ | Normal methods should have 'self', rather than 'x', as their first parameter. |
2+
| argument_names.py:53:5:53:20 | Function s_method | Normal methods should have 'self', rather than 'y', as their first parameter. |
3+
| argument_names.py:56:5:56:20 | Function s_method2 | Normal methods should have at least one parameter (the first of which should be 'self'). |
34
| om_test.py:71:5:71:19 | Function __repr__ | Normal methods should have at least one parameter (the first of which should be 'self'). |

python/ql/test/query-tests/Functions/general/argument_names.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ def n_smethod(ok):
1717
def n_cmethod(self):
1818
pass
1919

20+
# not ok
21+
@classmethod
22+
def n_cmethod2():
23+
pass
24+
2025
# this is allowed because it has a decorator other than @classmethod
2126
@classmethod
2227
@id
@@ -48,6 +53,9 @@ def __init__(x):
4853
def s_method(y):
4954
pass
5055

56+
def s_method2():
57+
pass
58+
5159
def s_ok(self):
5260
pass
5361

@@ -69,25 +77,32 @@ def s_cmethod2(cls):
6977

7078
#Possible FPs for non-self. ODASA-2439
7179

72-
class C(object):
80+
class Acceptable1(object):
7381
def _func(f):
7482
return f
75-
7683
_func(x)
7784

78-
#or
85+
class Acceptable2(object):
86+
def _func(f):
87+
return f
88+
7989
@_func
8090
def meth(self):
8191
pass
8292

83-
93+
# Handling methods defined in a different scope than the class it belongs to,
94+
# gets problmematic since we need to show the full-path from method definition
95+
# to actually adding it to the class. We tried to enable warnings for these in
96+
# September 2019, but ended up sticking to the decision from ODASA-2439 (where
97+
# results are both obvious and useful to the end-user).
8498
def dont_care(arg):
8599
pass
86100

87-
class C(object):
101+
class Acceptable3(object):
88102

89103
meth = dont_care
90104

105+
# OK
91106
class Meta(type):
92107

93108
#__new__ is an implicit class method, so the first arg is the metaclass

0 commit comments

Comments
 (0)