rspec/rules/S5878/python/rule.adoc

43 lines
1.0 KiB
Plaintext
Raw Normal View History

Function, methods and lambdas should not have too many mandatory parameters, i.e. parameters with no default value. Calling them will require code difficult to read and maintain. To solve this problem you could wrap some parameters in an object, split the function into simpler functions with less parameters or provide default values for some parameters.
2020-06-30 12:50:28 +02:00
== Noncompliant Code Example
With a maximum number of 4 parameters:
2020-06-30 12:50:28 +02:00
----
def do_something(param1, param2, param3, param4, param5): # Noncompliant
...
----
2020-06-30 12:50:28 +02:00
== Compliant Solution
----
def do_something(param1, param2, param3, param4):
...
# Or
def do_something(param1, param2, param3, param4, param5="a default value"):
...
----
2020-06-30 12:50:28 +02:00
== Exceptions
2021-01-27 13:42:22 +01:00
The first argument of non-static methods, i.e. ``++self++`` or ``++cls++``, is not counted as it is mandatory and it is passed automatically.
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::parameters.adoc[]
include::highlighting.adoc[]
endif::env-github,rspecator-view[]