:identifier_capital_plural: Local variables and function parameters :identifier: local variable and function parameter :identifier_plural: local variables and function parameters :identifier_or: local variable or function parameter :regex: ^[_a-z][a-z0-9_]*$ include::../introduction.adoc[] include::../why-is-this-an-issue.adoc[] include::../what-is-the-potential-impact.adoc[] === Exceptions Loop counters of one letter are ignored by this rule. [source,python] ---- for i in range(limit): # Compliant print(i) ---- Local variables matching regular expression ``++^[_A-Z][A-Z0-9_]*$++`` are considered as constant and ignored by this rule. + Function parameters are not concerned by this exception. [source,python] ---- def print_something(important_param): LOCAL_VARIABLE = "" # Compliant print(important_param + LOCAL_VARIABLE) ---- include::../how-to-fix-it.adoc[] === Code examples ==== Noncompliant code example With the default regular expression ``{regex}``: [source,python,diff-id=1,diff-type=noncompliant] ---- def print_something(IMPORTANT_PARAM): # Noncompliant localVariable = "" # Noncompliant print(IMPORTANT_PARAM + localVariable) ---- ==== Compliant solution [source,python,diff-id=1,diff-type=compliant] ---- def print_something(important_param): local_variable = "" print(important_param + local_variable) ---- == Resources === Documentation * Python Enhancement Proposals - https://peps.python.org/pep-0008/#naming-conventions[PEP8 - Naming Conventions] * Wikipedia - https://en.wikipedia.org/wiki/Naming_convention_(programming)[Naming Convention (programming)] === Related rules * S100 - Method names should comply with a naming convention * S101 - Class names should comply with a naming convention * S116 - Field names should comply with a naming convention * S1542 - Function names should comply with a naming convention * S1578 - Module names should comply with a naming convention * S2710 - The first argument to class methods should follow the naming convention ifdef::env-github,rspecator-view[] ''' == Implementation Specification (visible only on this page) include::../message.adoc[] include::../parameters.adoc[] ''' == Comments And Links (visible only on this page) include::../comments-and-links.adoc[] endif::env-github,rspecator-view[]