[refurb] Mark FURB180 fix unsafe when class has bases#18149
[refurb] Mark FURB180 fix unsafe when class has bases#18149ntBre merged 6 commits intoastral-sh:mainfrom
refurb] Mark FURB180 fix unsafe when class has bases#18149Conversation
|
@ntBre could you take a look at this PR when you're back? |
ntBre
left a comment
There was a problem hiding this comment.
Thanks, this makes sense to me! I just had one stylistic suggestion.
| return; | ||
| } | ||
|
|
||
| let has_bases = !class_def.bases().is_empty(); |
There was a problem hiding this comment.
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.
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.Protocoldoes) 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)