Skip to content

Conversation

@danparizher
Copy link
Contributor

@danparizher danparizher commented Jun 24, 2025

Summary

Closes #18739

Test Plan

@github-actions
Copy link
Contributor

github-actions bot commented Jun 24, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@danparizher danparizher changed the title [RUF055] could support equivalent cases using byte strings [RUF055] Support equivalent cases using byte strings Jun 24, 2025
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks pretty good overall. I just had a couple of nits and a larger concern about the escapes in byte strings.


if let Literal::Str(lit_str) = lit {
// Retain existing escape analysis for string replacement literals.
for (c, next) in lit_str.value.chars().tuple_windows() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this check applies to byte strings too. This is the thread that prompted these changes: #14679 (comment), and it looks like the escape there also works for byte strings:

>>> import re
>>> re.sub(b"foo", rb"\g<0>bar", b"foobar")
b'foobarbar'

so I don't think we can restrict this to the string literal case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean - I updated the logic to handle both str and bytes literals for the replacement argument by using match on the resolved literal.

@ntBre ntBre added rule Implementing or modifying a lint rule preview Related to preview mode features labels Jun 25, 2025
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I found a few more very small nits, but this is good to go otherwise.

danparizher and others added 4 commits July 18, 2025 11:56
…pression.rs

Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com>
…pression.rs

Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com>
@danparizher danparizher requested a review from ntBre July 18, 2025 16:19
@ntBre ntBre changed the title [RUF055] Support equivalent cases using byte strings [ruff] Support byte strings (RUF055) Jul 20, 2025
@ntBre ntBre merged commit 59249f4 into astral-sh:main Jul 20, 2025
35 checks passed
@danparizher danparizher deleted the implement-18739 branch July 20, 2025 22:01
dcreager added a commit that referenced this pull request Jul 21, 2025
* main: (25 commits)
  [ty] Sync vendored typeshed stubs (#19461)
  [ty] Extend tuple `__len__` and `__bool__` special casing to also cover tuple subclasses (#19289)
  [ty] bump docstring-adder pin (#19458)
  [ty] Disallow assignment to `Final` class attributes (#19457)
  Update dependency ruff to v0.12.4 (#19442)
  Update pre-commit hook astral-sh/ruff-pre-commit to v0.12.4 (#19443)
  Update rui314/setup-mold digest to 702b190 (#19441)
  Update taiki-e/install-action action to v2.56.19 (#19448)
  Update Rust crate strum_macros to v0.27.2 (#19447)
  Update Rust crate strum to v0.27.2 (#19446)
  Update Rust crate rand to v0.9.2 (#19444)
  Update Rust crate serde_json to v1.0.141 (#19445)
  Fix `unreachable` panic in parser (#19183)
  [`ruff`] Support byte strings (`RUF055`) (#18926)
  [ty] Avoid second lookup for `infer_maybe_standalone_expression` (#19439)
  [ty] Implemented "go to definition" support for import statements (#19428)
  [ty] Avoid secondary tree traversal to get call expression for keyword arguments (#19429)
  [ty] Add goto definition to playground (#19425)
  [ty] Add support for `@warnings.deprecated` (#19376)
  [ty] make `del x` force local resolution of `x` in the current scope (#19389)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Related to preview mode features rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RUF055 could support equivalent cases using byte strings

2 participants