[flake8-bugbear] Clarify RUF071 fix safety for non-path string comparisons#24149
Merged
MichaReiser merged 3 commits intoastral-sh:mainfrom Mar 27, 2026
Merged
Conversation
ntBre
reviewed
Mar 24, 2026
Contributor
ntBre
left a comment
There was a problem hiding this comment.
Thanks! This also looks good to me overall, but I had a couple of suggestions.
crates/ruff_linter/src/rules/ruff/rules/os_path_commonprefix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/ruff/rules/os_path_commonprefix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/ruff/rules/os_path_commonprefix.rs
Outdated
Show resolved
Hide resolved
|
Contributor
Author
|
@ntBre Thanks for the review! I have addressed all three points:
|
Add documentation explaining that os.path.commonprefix is valid for non-path string comparisons (e.g., version numbers, identifiers) and that RUF071 should be ignored in such cases. Adds a 'Fix safety' section documenting the semantic differences between commonprefix and commonpath with examples. Fixes astral-sh#24028
- Remove redundant non-path note (redundant with Fix safety section) - Link to general suppression docs instead of specific mechanisms - Fix incorrect ValueError claim: commonpath returns empty string
b00938b to
eb2125f
Compare
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 86.59%. The percentage of expected errors that received a diagnostic held steady at 80.96%. The number of fully passing files held steady at 68/132. |
Memory usage reportMemory usage unchanged ✅ |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-await |
40 | 0 | 0 |
invalid-return-type |
1 | 0 | 0 |
| Total | 41 | 0 | 0 |
Changes in flaky projects detected. Raw diff output excludes flaky projects; see the HTML report for details.
carljm
added a commit
that referenced
this pull request
Mar 31, 2026
* main: (40 commits) [ty] resolve union-likes in emitting union attribute errors (#24263) [ty] Improve support for `Callable` type context (#23888) [ty] Propagate type context through `await` expressions (#24256) [`pyflakes`] Flag annotated variable redeclarations as `F811` in preview mode (#24244) [ty] Preserve `Divergent` when materializing recursive aliases (#24245) Fix W391 fixes for consecutive empty notebook cells (#24236) [flake8-bugbear] Clarify RUF071 fix safety for non-path string comparisons (#24149) [ty] Ban type qualifiers in PEP-695 type aliases (#24242) [ty] Include keyword-prefixed symbols in completions for attributes (#24232) [ty] Add tests for TypedDict method overloads on unions (#24230) [ty] report unused bindings as unnecessary hint diagnostics (#23305) Remove unused `non_root` variable (#24238) Extend F507 to flag %-format strings with zero placeholders (#24215) [`flake8-simplify`] Suppress `SIM105` for `except*` before Python 3.12 (#23869) Ignore pre-initialization references in SIM113 (#24235) Parenthesize expression in RUF050 fix (#24234) Publish playgrounds using the `release-playground` environment (#24223) [ty] Fix instance-attribute lookup in methods of protocol classes (#24213) [ty] Used shared expression cache during generic call inference (#24219) [ty] make `Type::BoundMethod` include instances of same-named methods bound to a subclass (#24039) ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #24028
Added documentation explaining that
os.path.commonprefixis valid for non-path string comparisons (e.g., finding a common prefix among version numbers or identifiers), and thatos.path.commonpathcannot be used as a drop-in replacement in those cases since it raisesValueErroron non-path strings.Added a "Fix safety" section explaining why the fix is marked as unsafe, with concrete examples showing the semantic difference between
commonprefix(character-by-character) andcommonpath(path-component-level).Test Plan
Existing tests pass. Documentation change only (rule definition in
os_path_commonprefix.rs).