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

FP and wrong message on S2638 when positional-only parameters are used

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.8
    • Fix Version/s: None
    • Component/s: Rules
    • Labels:
      None

      Description

      In the following case the message is wrong:

      class ParentClassPosOnly(object):
          def mymethod(self, param1, /, param2, *, param3):
              pass
      
      class ChildClassPosOnlyMovedBad1(ParentClassPosOnly):
          def mymethod(self, param1, param2, /, *, param3):  # Noncompliant
              pass
      

      The current message is: "Make parameter param2 positional only."
      It should be: "Make parameter param2 keyword-or-positional."
      If it is too complex, "Change this method signature to accept the same arguments as the method it overrides." is ok.

      The following code raises a False Positive

      class ParentClassPosOnly(object):
          def mymethod(self, param1, /, param2, *, param3):
              pass
      
      class ChildClassPosOnlyToKworPos(ParentClassPosOnly):
          def mymethod(self, param1, param2, *, param3):  # False Positive
      

       param 1 can still be passed as positional. Liskov principle still works.

      Note that these use cases should be rare so this is a minor issue. No such issues were found on Peach.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                nicolas.harraudeau Nicolas Harraudeau
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: