Skip to content

Conversation

@Kalmaegi
Copy link
Contributor

Summary

add fix safety section to format_literals, for #15584

@Kalmaegi Kalmaegi changed the title add fix safety section to docs add fix safety section to format_literals docs Apr 17, 2025
@ntBre ntBre added the documentation Improvements or additions to documentation label Apr 18, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Apr 18, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre ntBre self-assigned this Apr 18, 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 was quite a tricky one, but I think I came up with a scenario where the rule is definitely unsafe. What do you think?

@Kalmaegi
Copy link
Contributor Author

I tested it again, and currently, sometimes the annotations are swapped, while other times they are not. There might be errors in cases where swapping occurs, but I think these are rare edge cases.
before:

def take_two(x: int, y: int) -> int:
    return x + y

def take_one(x: int) -> int:
    return x + 1

"{1}, {0}".format( # comment 1
    take_two(1, # comment 2
    2), # comment 3 
    take_one(1),
)

after:

def take_two(x: int, y: int) -> int:
    return x + y

def take_one(x: int) -> int:
    return x + 1

"{}, {}".format( # comment 1
    take_one(1), # comment 3 
take_two(1,  # comment 2
    2), 
)

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.

Very nice, thanks!

@ntBre ntBre changed the title add fix safety section to format_literals docs [pyupgrade] Add fix safety section to docs (UP030) Apr 21, 2025
@ntBre ntBre merged commit 2156100 into astral-sh:main Apr 21, 2025
22 checks passed
@ntBre ntBre mentioned this pull request Apr 21, 2025
71 tasks
dcreager added a commit that referenced this pull request Apr 22, 2025
* main: (37 commits)
  [red-knot] Add list of failing/slow ecosystem projects (#17474)
  [red-knot] mypy_primer: extend ecosystem checks (#17544)
  [red-knot] Move `InstanceType` to its own submodule (#17525)
  [red-knot] mypy_primer: capture backtraces (#17543)
  [red-knot] mypy_primer: Use upstream repo (#17500)
  [red-knot] `typing.dataclass_transform` (#17445)
  Update dependency react-resizable-panels to v2.1.8 (#17513)
  Update dependency smol-toml to v1.3.3 (#17505)
  Update dependency uuid to v11.1.0 (#17517)
  Update actions/setup-node action to v4.4.0 (#17514)
  [red-knot] Fix variable name (#17532)
  [red-knot] Add basic subtyping between class literal and callable (#17469)
  [`pyupgrade`] Add fix safety section to docs (`UP030`) (#17443)
  [`perflint`] Allow list function calls to be replaced with a comprehension (`PERF401`) (#17519)
  Update pre-commit dependencies (#17506)
  [red-knot] Simplify visibility constraint handling for `*`-import definitions (#17486)
  [red-knot] Detect (some) invalid protocols (#17488)
  [red-knot] Correctly identify protocol classes (#17487)
  Update dependency ruff to v0.11.6 (#17516)
  Update Rust crate shellexpand to v3.1.1 (#17512)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants