Python: Add more tests for cls/self argument names

This commit is contained in:
Rasmus Wriedt Larsen
2019-09-24 16:03:19 +02:00
parent 5271d6a063
commit 546405a379
3 changed files with 26 additions and 9 deletions

View File

@@ -1,2 +1,3 @@
| 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. |
| 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. |
| 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. |
| 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. |

View File

@@ -1,3 +1,4 @@
| argument_names.py:45:5:45:20 | Function __init__ | Normal methods should have 'self', rather than 'x', as their first parameter. |
| argument_names.py:48:5:48:20 | Function s_method | Normal methods should have 'self', rather than 'y', as their first parameter. |
| argument_names.py:50:5:50:20 | Function __init__ | Normal methods should have 'self', rather than 'x', as their first parameter. |
| argument_names.py:53:5:53:20 | Function s_method | Normal methods should have 'self', rather than 'y', as their first parameter. |
| 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'). |
| om_test.py:71:5:71:19 | Function __repr__ | Normal methods should have at least one parameter (the first of which should be 'self'). |

View File

@@ -17,6 +17,11 @@ class Normal(object):
def n_cmethod(self):
pass
# not ok
@classmethod
def n_cmethod2():
pass
# this is allowed because it has a decorator other than @classmethod
@classmethod
@id
@@ -48,6 +53,9 @@ class NonSelf(object):
def s_method(y):
pass
def s_method2():
pass
def s_ok(self):
pass
@@ -69,25 +77,32 @@ class NonSelf(object):
#Possible FPs for non-self. ODASA-2439
class C(object):
class Acceptable1(object):
def _func(f):
return f
_func(x)
class Acceptable2(object):
def _func(f):
return f
_func(x)
#or
@_func
def meth(self):
pass
# Handling methods defined in a different scope than the class it belongs to,
# gets problmematic since we need to show the full-path from method definition
# to actually adding it to the class. We tried to enable warnings for these in
# September 2019, but ended up sticking to the decision from ODASA-2439 (where
# results are both obvious and useful to the end-user).
def dont_care(arg):
pass
class C(object):
class Acceptable3(object):
meth = dont_care
# OK
class Meta(type):
#__new__ is an implicit class method, so the first arg is the metaclass