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

How to deal with counter-argument to rules? Concrete example PLC1901 #14602

Closed
kaddkaka opened this issue Nov 26, 2024 · 7 comments
Closed

How to deal with counter-argument to rules? Concrete example PLC1901 #14602

kaddkaka opened this issue Nov 26, 2024 · 7 comments
Labels
question Asking for support or clarification

Comments

@kaddkaka
Copy link

The pylint rule PLC1901 (compare-to-empty-string) checks for comparison with empty string which it considers "unnecessary", but I would argue this is not a problem, but rather the reverse!

Example code from documentation:

x: str = ...

if x == "":
    print("x is empty")

Even if the compared object is known to be a string or not, x == "" shows and explain the intent much better than not x.

  • If type annotation is missing, or or many lines away, the person reading the code will understand that this variable is meant to be a string. not x does not give any clue on what type x is supposed to be.

Could there be a section "Why is this not bad" in the documentation?

@kaddkaka
Copy link
Author

There has been complaints regarding PLC1901 in particular before: #4282 (comment)

@kaddkaka
Copy link
Author

Oh, I just found #5264

Is this rule still in "nursery"? Is PLC1901 meant to only be active if explicitly opt-in? I seem to get it just by having select "PL".

Nothing in the rule page documentation hints about this.

@MichaReiser MichaReiser added the question Asking for support or clarification label Nov 26, 2024
@MichaReiser
Copy link
Member

Hi @kaddkaka

Thanks for all the research and linking the relevant issues. That's useful.

Yes, the PLC rules aren't for everyone. They encode specific conventions that some find useful. There are many other rules in Ruff that are of a stylistic nature or are rather opinionated. We suggest you freely disable rules if you don't agree with what they're asserting.

@kaddkaka
Copy link
Author

@MichaReiser thanks, I agree this is the way to go. In the closed PR it was mentioned that this rule was moved to a "nursery". Does that corresponds to the rules enabled by --preview?

@MichaReiser
Copy link
Member

Yes, preview replaced the nursery concept and it is to opt-in to more experimental Ruff features and PLC1901 is one such experimental rule

@kaddkaka
Copy link
Author

Would it be valuable to have more rule categories here?

  1. rules that are new and not yet battle-tested (they enter in --preview and are moved to stable set of rules when mature)
  2. Some rules are considered not good and it's not valuable to include them in the "default" set of rules. these rules should perhaps be stable put "opt-in"

So instead of:

  • --preview and stable, have:
  • --preview, stable-default, stable-opt-in

@MichaReiser
Copy link
Member

MichaReiser commented Nov 28, 2024

Yes, we think that's the long term solution for this. We plan to recategorize rules but haven't gotten around to actually do it. See #1774

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for support or clarification
Projects
None yet
Development

No branches or pull requests

2 participants