-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[refurb
] add list of base class exceptions for FURB180
#18148
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
base: main
Are you sure you want to change the base?
[refurb
] add list of base class exceptions for FURB180
#18148
Conversation
36d80ed
to
5b17773
Compare
5b17773
to
03f6b77
Compare
@ntBre could you take a look at this PR when you're back? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this all makes sense to me! I just had a couple of minor suggestions.
|
Co-authored-by: Brent Westbrook <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is looking good. Just a couple more suggestions, and one question about naming
...linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB180_FURB180.py.snap
Outdated
Show resolved
Hide resolved
refurb
] add list of base class exceptions for FURB180
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks again! This is good to go from my perspective, modulo any further bike-shedding on the name.
@ntBre Just want to make sure this is still on your radar 👀 |
Oh yes, thank you! Let me actually cc someone who might have an opinion on the name (@MichaReiser any thoughts on the names and maybe the two separate options?) I believe the current state is that we added two new config options:
|
/// Expects to receive a list of fully-qualified names (e.g., `typing.Protocol`, rather than | ||
/// `Protocol`). | ||
#[option( | ||
default = r#"["typing.Protocol", "typing_extensions.Protocol"]"#, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to gate this behind preview, given that we now emit fewer lints (which can lead to unused noqa comments) or do we consider this a bug fix?
From our versioning policy
A new configuration option is added in a backwards compatible way (no formatting changes or new lint errors)
So I think we need to gate this behind preview
I'm not entirely sure I understnad what you want feedback on. I see that this PR introduces two new options. Are you asking for my opinion on the option names? Is there mroe feedback that you're looking for? Looking at the issue #13307 (comment) it's unclear if we want these options. More specifically, options have a non-zero cost because users need to understand them. This PR also changes the default for everyone using the rule, which may not what they want. |
That's a fair point. I figured if users are in the situation where this becomes relevant, they have code along the lines of class Foo(Protocol, metaclass=ABCMeta): ... I imagine if a user wants this to be linted, the lint shouldn't be "use ABC as a base instead of ABCMeta", but rather "don't bother specifying ABC/ABCMeta if the base(s) already includes ABC in the class hierarchy". |
Summary
Add a config option
tool.ruff.lint.refurb.allow-abc-meta-bases
(["typing.Protocol", "typing_extensions.Protocol"]
by default) that allows to specify a list such that if class has at least one base-class and all base-classes are in this list it is exempt fromFURB180
. This is useful for classes that validate their base-classes at runtime such as the two that are the default value.Test Plan
Besides the adjusted test
ruff_linter::rules::refurb::tests::rules
, I created a minimal Python project to test the configuration option.References
Fixes #13307 (together with #18149)