Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyCharm inspections #3040

Open
matthewlloyd opened this issue Feb 19, 2023 · 2 comments
Open

PyCharm inspections #3040

matthewlloyd opened this issue Feb 19, 2023 · 2 comments
Labels
needs-decision Awaiting a decision from a maintainer plugin Implementing a known but unsupported plugin

Comments

@matthewlloyd
Copy link
Contributor

(Opening a new issue to continue the discussion from #2972 which will be closed by #3022)

I went through all the PyCharm inspections, filtered those I deemed implementable in a non-type-aware linter, and categorized them by whether they have Ruff or PyLint counterparts, mostly by running Ruff and PyLint directly on the examples provided in the PyCharm Settings panel.

There were five left over, which might merit consideration for inclusion as RUF rules.

PyCharm inspections not currently covered by Ruff or PyLint

  • Class-specific decorator is used outside the class (@classmethod or @staticmethod)
    @staticmethod
    def a(): pass
  • Incorrect property definition (e.g. getter that does not return or yield a value)
    class A:
        @property
        def field(): pass
  • Invalid definition of 'typing.NamedTuple' (field with default followed by one or more fields without)
    import typing
    
    class FullName(typing.NamedTuple):
        first: str
        last: str = ""
        middle: str
  • Non-optimal list declaration
    l = [1]
    l.append(2)
  • Shadowing names from outer scopes
    def outer(p):
      def inner(p):
          pass

Covered by Ruff or PyLint

  • Assignments to 'for' loop or 'with' statement parameter (see above)
    • PLW2901 redefined-loop-name
  • Assignment can be replaced with augmented assignment (a = a + b becomes a += b; arguably less useful)
    • PLR6104 consider-using-augmented-assign
  • Dictionary contains duplicate keys ({'a': 1, 'a': 2})
    • PLW0109 duplicate-key
  • First argument of the method is reassigned (e.g. reassignment to self)
    • PLW0642 self-cls-assignment
  • init method that returns a value
    • PLE101 return-in-init
  • Method is not declared static (but does not use self)
    • PLR6301 no-self-use
    • PLW0211 bad-staticmethod-argument (not quite the same thing)
  • Missed call to 'init' of the super class
    • PLW0231 super-init-not-called
  • Redeclared names without usages (def x(): pass, followed later by x = 2, no uses in between)
    • F811
  • Redundant boolean variable check (if b == True)
    • PLC0121 singleton-comparison
  • Redundant parentheses
    • UP034
  • Statement has no effect (e.g. comprises solely a variable name)
    • PLW0104 pointless-statement
    • also B018 as above
  • Too complex chained comparisons ((x >= 0 and x <= 1) becomes (0 <= x <= 1)).
    • PLR1716 chained-comparison
  • Unnecessary backslash - backslashes in places where line continuation is implicit inside (), [], and {}.
    • PyLint does not detect this, but pycodestyle has E502: "The backslash is redundant between brackets" (not yet implemented in Ruff)
@charliermarsh
Copy link
Member

Thank you for this, super thorough and much appreciated!

@charliermarsh charliermarsh added the plugin Implementing a known but unsupported plugin label Feb 19, 2023
@charliermarsh charliermarsh added the needs-decision Awaiting a decision from a maintainer label Jul 10, 2023
@pkulev
Copy link

pkulev commented Jan 17, 2024

I'm looking forward to see those checks in ruff!
I'll expand here some moments regarding F811 and similar check in pycharm.

In the following example all redeclarations were highlighted by pycharm, but ruff alerts only on imports and function/class definitions. Variable redeclaration without usage passes the check.

import os
import sys
import os  # ruff alerts F811

def foo():
    pass

def foo():  # ruff alerts F811
    pass

class Foo:
    pass

class Foo:  # ruff alerts F811
    pass

class Bar:
    x = 10
    x = 20  # No alert

BAR = "bar"
BAR = "baz"  # No alert

It would be great to enable checking for variables too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-decision Awaiting a decision from a maintainer plugin Implementing a known but unsupported plugin
Projects
None yet
Development

No branches or pull requests

3 participants