mirror of
https://github.com/github/codeql.git
synced 2026-05-05 05:35:13 +02:00
Python: Consistenly use parameter instead of argument in docs
The Python 3 FAQ states that this is the right thing [0] It sadly doesn't align 100% with PEP8, which calls them for "arguments" [1], but after discussion with Taus, we decided to go with "parameter" everywhere to be consistent. [0] https://docs.python.org/3/faq/programming.html#faq-argument-vs-parameter [1] https://www.python.org/dev/peps/pep-0008/#function-and-method-arguments
This commit is contained in:
@@ -5,14 +5,14 @@
|
||||
|
||||
|
||||
<overview>
|
||||
<p> The first argument of a class method, a new method or any metaclass method
|
||||
should be called <code>cls</code>. This makes the purpose of the argument clear to other developers.
|
||||
<p> The first parameter of a class method, a new method or any metaclass method
|
||||
should be called <code>cls</code>. This makes the purpose of the parameter clear to other developers.
|
||||
</p>
|
||||
|
||||
</overview>
|
||||
<recommendation>
|
||||
|
||||
<p>Change the name of the first argument to <code>cls</code> as recommended by the style guidelines
|
||||
<p>Change the name of the first parameter to <code>cls</code> as recommended by the style guidelines
|
||||
in PEP 8.</p>
|
||||
|
||||
</recommendation>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @name First parameter of a class method is not named 'cls'
|
||||
* @description Using an alternative name for the first argument of a class method makes code more
|
||||
* difficult to read; PEP8 states that the first argument to class methods should be 'cls'.
|
||||
* @description Using an alternative name for the first parameter of a class method makes code more
|
||||
* difficult to read; PEP8 states that the first parameter to class methods should be 'cls'.
|
||||
* @kind problem
|
||||
* @tags maintainability
|
||||
* readability
|
||||
@@ -38,10 +38,10 @@ not first_arg_cls(f) and classmethod_decorators_only(f) and
|
||||
not f.getName() = "__new__" and
|
||||
(
|
||||
if exists(f.getArgName(0)) then
|
||||
message = "Class methods or methods of a type deriving from type should have 'cls', rather than '" +
|
||||
f.getArgName(0) + "', as their first argument."
|
||||
message = "Class methods or methods of a type deriving from type should have 'cls', rather than '" +
|
||||
f.getArgName(0) + "', as their first parameter."
|
||||
else
|
||||
message = "Class methods or methods of a type deriving from type should have 'cls' as their first argument."
|
||||
message = "Class methods or methods of a type deriving from type should have 'cls' as their first parameter."
|
||||
)
|
||||
|
||||
select f, message
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
class Point:
|
||||
def __init__(val, x, y): # first argument is mis-named 'val'
|
||||
def __init__(val, x, y): # first parameter is mis-named 'val'
|
||||
val._x = x
|
||||
val._y = y
|
||||
|
||||
|
||||
class Point2:
|
||||
def __init__(self, x, y): # first argument is correctly named 'self'
|
||||
def __init__(self, x, y): # first parameter is correctly named 'self'
|
||||
self._x = x
|
||||
self._y = y
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @name First argument of a method is not named 'self'
|
||||
* @description Using an alternative name for the first argument of an instance method makes
|
||||
* code more difficult to read; PEP8 states that the first argument to instance
|
||||
* @name First parameter of a method is not named 'self'
|
||||
* @description Using an alternative name for the first parameter of an instance method makes
|
||||
* code more difficult to read; PEP8 states that the first parameter to instance
|
||||
* methods should be 'self'.
|
||||
* @kind problem
|
||||
* @tags maintainability
|
||||
|
||||
@@ -1,3 +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: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. |
|
||||
| parameter_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 parameter. |
|
||||
| parameter_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 parameter. |
|
||||
| parameter_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 parameter. |
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
| 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'). |
|
||||
| parameter_names.py:50:5:50:20 | Function __init__ | Normal methods should have 'self', rather than 'x', as their first parameter. |
|
||||
| parameter_names.py:53:5:53:20 | Function s_method | Normal methods should have 'self', rather than 'y', as their first parameter. |
|
||||
| parameter_names.py:56:5:56:20 | Function s_method2 | Normal methods should have at least one parameter (the first of which should be 'self'). |
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Using name other than 'self' for first argument in methods.
|
||||
# This shouldn't apply to classmethods (first argument should be 'cls' or similar)
|
||||
# or static methods (first argument can be anything)
|
||||
# Using name other than 'self' for first parameter in methods.
|
||||
# This shouldn't apply to classmethods (first parameter should be 'cls' or similar)
|
||||
# or static methods (first parameter can be anything)
|
||||
|
||||
|
||||
class Normal(object):
|
||||
Reference in New Issue
Block a user