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

[pylint] Do not report methods with only one EM101-compatible raise (PLR6301) #15507

Merged
merged 1 commit into from
Jan 17, 2025

Conversation

InSyncWithFoo
Copy link
Contributor

@InSyncWithFoo InSyncWithFoo commented Jan 15, 2025

Summary

Related to this comment by @DaniBodor at #12172. Tests adapted from that of #13714.

Test Plan

cargo nextest run and cargo insta test.

Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this change but I'm not convinced this goes into the right direction.

Taking the exmaples from your tests. The self parameter is unused and unnecessary because Foo doesn't extend any base class. That's why I think this is in the spirit of PLR6301 to flag the self usage. I can see how the warning is annoying when prototyping an API but I'd simply ignore the warning in that case (either using a noqa or literally ignoring the warning).

The other case is where Foo extends from a base class but our recommendation there is to mark the method as @override.

That's why I think we should leave the rule as is but I'm interested in your perspective.

@MichaReiser MichaReiser added rule Implementing or modifying a lint rule needs-decision Awaiting a decision from a maintainer labels Jan 16, 2025
@InSyncWithFoo
Copy link
Contributor Author

InSyncWithFoo commented Jan 16, 2025

I still advocate for this change, as it improves consistency. Currently this triggers PLR6301 but not ARG002:

class Foo:
    # PLR6301: Method `lorem` could be a function, class method, or static method
    def lorem(self, v):
        msg = 'Lorem ipsum dolor sit amet'
        raise NotImplementedError(msg)

This triggers both:

class Foo:
    # PLR6301: Method `lorem` could be a function, class method, or static method
    def lorem(self, v):  # Unused method argument: `v`
        print(1 + 2)

@MichaReiser MichaReiser added preview Related to preview mode features and removed needs-decision Awaiting a decision from a maintainer labels Jan 17, 2025
@MichaReiser MichaReiser merged commit dbfdaad into astral-sh:main Jan 17, 2025
21 checks passed
@InSyncWithFoo InSyncWithFoo deleted the PLR6301 branch January 17, 2025 12:53
dcreager added a commit that referenced this pull request Jan 17, 2025
* main:
  [red-knot] Inline `SubclassOfType::as_instance_type_of_metaclass()` (#15556)
  [`flake8-comprehensions`] strip parentheses around generators in `unnecessary-generator-set` (`C401`) (#15553)
  [`pylint`] Implement `redefined-slots-in-subclass` (`W0244`) (#9640)
  [`flake8-bugbear`] Do not raise error if keyword argument is present and target-python version is less or equals than 3.9 (`B903`) (#15549)
  [red-knot] `type[T]` is disjoint from `type[S]` if the metaclass of `T` is disjoint from the metaclass of `S` (#15547)
  [red-knot] Pure instance variables declared in class body (#15515)
  Update snapshots of #15507 with new annotated snipetts rendering (#15546)
  [`pylint`] Do not report methods with only one `EM101`-compatible `raise` (`PLR6301`) (#15507)
  Fix unstable f-string formatting for expressions containing a trailing comma (#15545)
  Support `knot.toml` files in project discovery (#15505)
  Add support for configuring knot in `pyproject.toml` files (#15493)
  Fix bracket spacing for single-element tuples in f-string expressions (#15537)
  [`flake8-simplify`] Do not emit diagnostics for expressions inside string type annotations (`SIM222`, `SIM223`) (#15405)
  [`flake8-pytest-style`] Do not emit diagnostics for empty `for` loops (`PT012`, `PT031`) (#15542)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Related to preview mode features rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants