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

S2201 should detect unused "bytes" methods when variables are used, as well as dict.fromkeys and dict.get

    Details

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

      Description

      S2201 should raise on the following "bytes" methods when variables are used: capitalize, center, count, decode, endswith, expandtabs, find, fromhex, hex, index, isalnum, isalpha, isascii, isdigit, islower, isspace, istitle, isupper, join, ljust, lower, lstrip, maketrans, partition, replace, rfind, rindex, rjust, rpartition, rsplit, rstrip, split, splitlines, startswith, strip, swapcase, title, translate, upper, zfill

      def bytes_methods():
          b = b"bytes"
          b.capitalize()  # Noncompliant
          b.center(20)  # Noncompliant
          b.count(b'b')  # Noncompliant
          b.decode()  # Noncompliant
          b.endswith(b'es')  # Noncompliant
          b'a\t\tb'.expandtabs(2)  # Noncompliant
          b.find(b'y')  # Noncompliant
          bytes.fromhex(b.hex())  # Noncompliant
          b.hex()  # Noncompliant
          b.index(b'y')  # Noncompliant
          b.isalnum()  # Noncompliant
          b.isalpha()  # Noncompliant
          b.isascii()  # Noncompliant
          b.isdigit()  # Noncompliant
          b.islower()  # Noncompliant
          b.isspace()  # Noncompliant
          b.istitle()  # Noncompliant
          b.isupper()  # Noncompliant
          b.join([b'1', b'2'])  # Noncompliant
          b.ljust(20)  # Noncompliant
          b.lower()  # Noncompliant
          b.lstrip()  # Noncompliant
          bytes.maketrans(b'bytes', b'setyb')  # Noncompliant
          b.partition(b'y')  # Noncompliant
          b.replace(b'b', b'42')  # Noncompliant
          b.rfind(b'y')  # Noncompliant
          b.rindex(b'y')  # Noncompliant
          b.rjust(20)  # Noncompliant
          b.rpartition(b'y')  # Noncompliant
          b.rsplit(b'y')  # Noncompliant
          b.rstrip()  # Noncompliant
          b.split(b'y')  # Noncompliant
          b'line1\nline2'.splitlines()  # Noncompliant
          b.startswith(b'by')  # Noncompliant
          b.strip()  # Noncompliant
          b.swapcase()  # Noncompliant
          b.title()  # Noncompliant
          b.translate(bytes.maketrans(b'bytes', b'setyb'))  # Noncompliant
          b.upper()  # Noncompliant
          b.zfill(20)  # Noncompliant
      
          b[1]  # Noncompliant. __getitem__ method
          b'y' in b  # Noncompliant. __contains__ method
      

       

      S2201 should also raise on the following dict methods: fromkeys, get

          dict.fromkeys([1, 2, 3, 4], 'value')  # Noncompliant
          d.get('a')  # Noncompliant
      

        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: