-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[refurb
] Mark FURB180
fix unsafe when class has bases
#18149
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
Conversation
@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 makes sense to me! I just had one stylistic suggestion.
@@ -69,6 +74,7 @@ pub(crate) fn metaclass_abcmeta(checker: &Checker, class_def: &StmtClassDef) { | |||
return; | |||
} | |||
|
|||
let has_bases = !class_def.bases().is_empty(); |
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.
nit: I think we could use something like this here:
let has_bases = !class_def.bases().is_empty(); | |
let applicability = if class_def.bases().is_empty() { Applicability::Safe } else { Applicability::Unsafe }; |
And then instead of the make_fix
method, we can just use Fix::applicable_edits
where we previously used Fix::safe_edits
. You could then move your comments from make_fix
here too, or possibly delete them too since I think you covered it nicely in the Fix safety
section.
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.
Thank you very much. Nit happily applied.
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
FURB180 | 24 | 0 | 0 | 0 | 24 |
refurb
] Mark FURB180
fix unsafe when class has bases
…aration * origin/main: [ty] Infer `list[T]` when unpacking non-tuple type (#18438) [ty] Meta-type of type variables should be type[..] (#18439) [`pyupgrade`] Make fix unsafe if it deletes comments (`UP050`) (#18390) [`pyupgrade`] Make fix unsafe if it deletes comments (`UP004`) (#18393) [ty] Support using legacy typing aliases for generic classes in type annotations (#18404) Use ty's completions in playground (#18425) Update editor setup docs about Neovim and Vim (#18324) Update NPM Development dependencies (#18423) Infer `list[T]` for starred target in unpacking (#18401) [`refurb`] Mark `FURB180` fix unsafe when class has bases (#18149) [`fastapi`] Avoid false positive for class dependencies (`FAST003`) (#18271)
Summary
Mark
FURB180
's fix as unsafe if the class already has base classes. This is because the base classes might validate the other base classes (liketyping.Protocol
does) or otherwise alter runtime behavior if more base classes are added.Test Plan
The existing snapshot test covers this case already.
References
Partially addresses #13307 (left out way to permit certain exceptions)