Uploaded image for project: 'SonarPython'
  1. SonarPython
  2. SONARPY-586

Rule S2710: The first argument to class methods should follow the naming convention

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.8
    • Component/s: Rules
    • Labels:

      Description

      Note that a before decorators existed, the only way to create a class method was:

      class MyClass:
          def old_style_class_method(cls):
              print("old_style_class_method")
          old_style_class_method = classmethod(old_style_class_method)
      

      classmethod is used after the method is defined to replace it with a decorated version.

      This is however out of scope as we could have some false positives:

      • The PEP-318 specifying decorators was created in 2003.
      • PEP-8 which defines "cls" as the standard name for class methods was created in 2001.

      The two PEP are too close in time. Any code not using decorators has a higher chance of also not using "cls" as its class methods' parameter.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              guillaume.dequenne Guillaume Dequenne
              Reporter:
              nicolas.harraudeau Nicolas Harraudeau (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved: