Skip to content

Comments

[pyupgrade] Better messages and diagnostic range (UP015)#15872

Merged
MichaReiser merged 2 commits intoastral-sh:mainfrom
InSyncWithFoo:UP015
Feb 5, 2025
Merged

[pyupgrade] Better messages and diagnostic range (UP015)#15872
MichaReiser merged 2 commits intoastral-sh:mainfrom
InSyncWithFoo:UP015

Conversation

@InSyncWithFoo
Copy link
Contributor

Summary

Resolves #15863.

In preview, diagnostic ranges will now be limited to that of the argument. Rule documentation, variable names, error messages and fix titles have all been modified to use "argument" consistently.

Test Plan

cargo nextest run and cargo insta test.

@InSyncWithFoo
Copy link
Contributor Author

Is it necessary to add a "Preview" section to the rule documentation?

@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2025

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+55 -55 violations, +0 -0 fixes in 3 projects; 52 projects unchanged)

binary-husky/gpt_academic (+46 -46 violations, +0 -0 fixes)

+ check_proxy.py:161:14: UP015 [*] Unnecessary mode argument
- check_proxy.py:161:14: UP015 [*] Unnecessary open mode parameters
+ check_proxy.py:191:14: UP015 [*] Unnecessary mode argument
- check_proxy.py:191:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/Conversation_To_File.py:73:14: UP015 [*] Unnecessary mode argument
- crazy_functions/Conversation_To_File.py:73:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/Conversation_To_File.py:87:10: UP015 [*] Unnecessary mode argument
- crazy_functions/Conversation_To_File.py:87:10: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/Latex_Project_Polish.py:66:14: UP015 [*] Unnecessary mode argument
- crazy_functions/Latex_Project_Polish.py:66:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/Latex_Project_Translate_Legacy.py:46:14: UP015 [*] Unnecessary mode argument
- crazy_functions/Latex_Project_Translate_Legacy.py:46:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/Markdown_Translate.py:61:14: UP015 [*] Unnecessary mode argument
- crazy_functions/Markdown_Translate.py:61:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/SourceCode_Analyse.py:22:14: UP015 [*] Unnecessary mode argument
- crazy_functions/SourceCode_Analyse.py:22:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/SourceCode_Comment.py:33:14: UP015 [*] Unnecessary mode argument
- crazy_functions/SourceCode_Comment.py:33:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/SourceCode_Comment.py:79:14: UP015 [*] Unnecessary mode argument
- crazy_functions/SourceCode_Comment.py:79:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/agent_fns/python_comment_agent.py:207:14: UP015 [*] Unnecessary mode argument
- crazy_functions/agent_fns/python_comment_agent.py:207:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/ast_fns/comment_remove.py:48:10: UP015 [*] Unnecessary mode argument
- crazy_functions/ast_fns/comment_remove.py:48:10: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/latex_fns/latex_actions.py:239:10: UP015 [*] Unnecessary mode argument
- crazy_functions/latex_fns/latex_actions.py:239:10: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/latex_fns/latex_actions.py:322:14: UP015 [*] Unnecessary mode argument
- crazy_functions/latex_fns/latex_actions.py:322:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/latex_fns/latex_actions.py:358:18: UP015 [*] Unnecessary mode argument
- crazy_functions/latex_fns/latex_actions.py:358:18: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/latex_fns/latex_toolbox.py:294:14: UP015 [*] Unnecessary mode argument
- crazy_functions/latex_fns/latex_toolbox.py:294:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/latex_fns/latex_toolbox.py:321:18: UP015 [*] Unnecessary mode argument
- crazy_functions/latex_fns/latex_toolbox.py:321:18: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/latex_fns/latex_toolbox.py:386:22: UP015 [*] Unnecessary mode argument
- crazy_functions/latex_fns/latex_toolbox.py:386:22: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/pdf_fns/parse_pdf_via_doc2x.py:250:18: UP015 [*] Unnecessary mode argument
- crazy_functions/pdf_fns/parse_pdf_via_doc2x.py:250:18: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/pdf_fns/parse_pdf_via_doc2x.py:269:18: UP015 [*] Unnecessary mode argument
- crazy_functions/pdf_fns/parse_pdf_via_doc2x.py:269:18: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/pdf_fns/parse_pdf_via_doc2x.py:298:18: UP015 [*] Unnecessary mode argument
... 51 additional changes omitted for project

latchbio/latch (+8 -8 violations, +0 -0 fixes)

+ src/latch/executions.py:56:14: UP015 [*] Unnecessary mode argument
- src/latch/executions.py:56:14: UP015 [*] Unnecessary open mode parameters
+ src/latch_cli/exceptions/traceback.py:24:14: UP015 [*] Unnecessary mode argument
- src/latch_cli/exceptions/traceback.py:24:14: UP015 [*] Unnecessary open mode parameters
+ src/latch_cli/main.py:975:10: UP015 [*] Unnecessary mode argument
- src/latch_cli/main.py:975:10: UP015 [*] Unnecessary open mode parameters
+ src/latch_cli/services/get_executions.py:377:14: UP015 [*] Unnecessary mode argument
- src/latch_cli/services/get_executions.py:377:14: UP015 [*] Unnecessary open mode parameters
+ src/latch_cli/services/launch.py:48:10: UP015 [*] Unnecessary mode argument
- src/latch_cli/services/launch.py:48:10: UP015 [*] Unnecessary open mode parameters
... 6 additional changes omitted for project

milvus-io/pymilvus (+1 -1 violations, +0 -0 fixes)

+ examples/bulk_import/example_bulkwriter.py:263:18: UP015 [*] Unnecessary mode argument
- examples/bulk_import/example_bulkwriter.py:263:18: UP015 [*] Unnecessary open mode parameters

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
UP015 110 55 55 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+55 -55 violations, +0 -0 fixes in 3 projects; 52 projects unchanged)

binary-husky/gpt_academic (+46 -46 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

- check_proxy.py:161:14: UP015 [*] Unnecessary open mode parameters
+ check_proxy.py:161:32: UP015 [*] Unnecessary mode argument
- check_proxy.py:191:14: UP015 [*] Unnecessary open mode parameters
+ check_proxy.py:191:32: UP015 [*] Unnecessary mode argument
- crazy_functions/Conversation_To_File.py:73:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/Conversation_To_File.py:73:30: UP015 [*] Unnecessary mode argument
- crazy_functions/Conversation_To_File.py:87:10: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/Conversation_To_File.py:87:26: UP015 [*] Unnecessary mode argument
- crazy_functions/Latex_Project_Polish.py:66:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/Latex_Project_Polish.py:66:23: UP015 [*] Unnecessary mode argument
- crazy_functions/Latex_Project_Translate_Legacy.py:46:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/Latex_Project_Translate_Legacy.py:46:23: UP015 [*] Unnecessary mode argument
- crazy_functions/Markdown_Translate.py:61:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/Markdown_Translate.py:61:23: UP015 [*] Unnecessary mode argument
- crazy_functions/SourceCode_Analyse.py:22:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/SourceCode_Analyse.py:22:23: UP015 [*] Unnecessary mode argument
- crazy_functions/SourceCode_Comment.py:33:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/SourceCode_Comment.py:33:23: UP015 [*] Unnecessary mode argument
- crazy_functions/SourceCode_Comment.py:79:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/SourceCode_Comment.py:79:76: UP015 [*] Unnecessary mode argument
- crazy_functions/agent_fns/python_comment_agent.py:207:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/agent_fns/python_comment_agent.py:207:25: UP015 [*] Unnecessary mode argument
- crazy_functions/ast_fns/comment_remove.py:48:10: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/ast_fns/comment_remove.py:48:28: UP015 [*] Unnecessary mode argument
- crazy_functions/latex_fns/latex_actions.py:239:10: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/latex_fns/latex_actions.py:239:24: UP015 [*] Unnecessary mode argument
- crazy_functions/latex_fns/latex_actions.py:322:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/latex_fns/latex_actions.py:322:29: UP015 [*] Unnecessary mode argument
- crazy_functions/latex_fns/latex_actions.py:358:18: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/latex_fns/latex_actions.py:358:33: UP015 [*] Unnecessary mode argument
- crazy_functions/latex_fns/latex_toolbox.py:294:14: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/latex_fns/latex_toolbox.py:294:25: UP015 [*] Unnecessary mode argument
- crazy_functions/latex_fns/latex_toolbox.py:321:18: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/latex_fns/latex_toolbox.py:321:29: UP015 [*] Unnecessary mode argument
- crazy_functions/latex_fns/latex_toolbox.py:386:22: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/latex_fns/latex_toolbox.py:386:32: UP015 [*] Unnecessary mode argument
- crazy_functions/pdf_fns/parse_pdf_via_doc2x.py:250:18: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/pdf_fns/parse_pdf_via_doc2x.py:250:37: UP015 [*] Unnecessary mode argument
- crazy_functions/pdf_fns/parse_pdf_via_doc2x.py:269:18: UP015 [*] Unnecessary open mode parameters
+ crazy_functions/pdf_fns/parse_pdf_via_doc2x.py:269:37: UP015 [*] Unnecessary mode argument
- crazy_functions/pdf_fns/parse_pdf_via_doc2x.py:298:18: UP015 [*] Unnecessary open mode parameters
... 51 additional changes omitted for project

latchbio/latch (+8 -8 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

- src/latch/executions.py:56:14: UP015 [*] Unnecessary open mode parameters
+ src/latch/executions.py:56:36: UP015 [*] Unnecessary mode argument
- src/latch_cli/exceptions/traceback.py:24:14: UP015 [*] Unnecessary open mode parameters
+ src/latch_cli/exceptions/traceback.py:24:34: UP015 [*] Unnecessary mode argument
- src/latch_cli/main.py:975:10: UP015 [*] Unnecessary open mode parameters
+ src/latch_cli/main.py:975:57: UP015 [*] Unnecessary mode argument
- src/latch_cli/services/get_executions.py:377:14: UP015 [*] Unnecessary open mode parameters
+ src/latch_cli/services/get_executions.py:377:29: UP015 [*] Unnecessary mode argument
- src/latch_cli/services/launch.py:48:10: UP015 [*] Unnecessary open mode parameters
+ src/latch_cli/services/launch.py:48:28: UP015 [*] Unnecessary mode argument
... 6 additional changes omitted for project

milvus-io/pymilvus (+1 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

- examples/bulk_import/example_bulkwriter.py:263:18: UP015 [*] Unnecessary open mode parameters
+ examples/bulk_import/example_bulkwriter.py:263:34: UP015 [*] Unnecessary mode argument

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
UP015 110 55 55 0 0

@MichaReiser MichaReiser added preview Related to preview mode features diagnostics Related to reporting of diagnostics. labels Feb 3, 2025
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Thanks. A few small nits but overall this looks good

@MichaReiser MichaReiser merged commit 44ddd98 into astral-sh:main Feb 5, 2025
21 checks passed
@InSyncWithFoo InSyncWithFoo deleted the UP015 branch February 5, 2025 17:11
MichaReiser added a commit that referenced this pull request Mar 13, 2025
…P015`) (#16672)

## Summary

This PR stabilizes the behavior change introduced in
#15872

The diagnostic range is now the range of the redundant `mode` argument
where it previously was the range of the entire `open` call:

Before:

```
UP015.py:2:1: UP015 [*] Unnecessary mode argument
  |
1 | open("foo", "U")
2 | open("foo", "Ur")
  | ^^^^^^^^^^^^^^^^^ UP015
3 | open("foo", "Ub")
4 | open("foo", "rUb")
  |
  = help: Remove mode argument
```


Now:

```
UP015.py:2:13: UP015 [*] Unnecessary mode argument
  |
1 | open("foo", "U")
2 | open("foo", "Ur")
  |             ^^^^ UP015
3 | open("foo", "Ub")
4 | open("foo", "rUb")
  |
  = help: Remove mode argument
```

This is a breaking change because it may require moving a `noqa` comment
onto a different line, e.g if you have

```py
open(
    "foo",
    "Ur",
) # noqa: UP015
```

Needs to be rewritten to 

```py
open(
    "foo",
    "Ur", # noqa: UP015
)
```

There have been now new issues or PRs since the new preview behavior was
implemented. It first was released as part of Ruff 0.9.5 on the 5th of
Feb (a little more than a month ago)

## Test Plan

I reviewed the snapshot tests
MichaReiser added a commit that referenced this pull request Mar 13, 2025
…P015`) (#16672)

## Summary

This PR stabilizes the behavior change introduced in
#15872

The diagnostic range is now the range of the redundant `mode` argument
where it previously was the range of the entire `open` call:

Before:

```
UP015.py:2:1: UP015 [*] Unnecessary mode argument
  |
1 | open("foo", "U")
2 | open("foo", "Ur")
  | ^^^^^^^^^^^^^^^^^ UP015
3 | open("foo", "Ub")
4 | open("foo", "rUb")
  |
  = help: Remove mode argument
```


Now:

```
UP015.py:2:13: UP015 [*] Unnecessary mode argument
  |
1 | open("foo", "U")
2 | open("foo", "Ur")
  |             ^^^^ UP015
3 | open("foo", "Ub")
4 | open("foo", "rUb")
  |
  = help: Remove mode argument
```

This is a breaking change because it may require moving a `noqa` comment
onto a different line, e.g if you have

```py
open(
    "foo",
    "Ur",
) # noqa: UP015
```

Needs to be rewritten to 

```py
open(
    "foo",
    "Ur", # noqa: UP015
)
```

There have been now new issues or PRs since the new preview behavior was
implemented. It first was released as part of Ruff 0.9.5 on the 5th of
Feb (a little more than a month ago)

## Test Plan

I reviewed the snapshot tests
MichaReiser added a commit that referenced this pull request Mar 13, 2025
…P015`) (#16672)

## Summary

This PR stabilizes the behavior change introduced in
#15872

The diagnostic range is now the range of the redundant `mode` argument
where it previously was the range of the entire `open` call:

Before:

```
UP015.py:2:1: UP015 [*] Unnecessary mode argument
  |
1 | open("foo", "U")
2 | open("foo", "Ur")
  | ^^^^^^^^^^^^^^^^^ UP015
3 | open("foo", "Ub")
4 | open("foo", "rUb")
  |
  = help: Remove mode argument
```


Now:

```
UP015.py:2:13: UP015 [*] Unnecessary mode argument
  |
1 | open("foo", "U")
2 | open("foo", "Ur")
  |             ^^^^ UP015
3 | open("foo", "Ub")
4 | open("foo", "rUb")
  |
  = help: Remove mode argument
```

This is a breaking change because it may require moving a `noqa` comment
onto a different line, e.g if you have

```py
open(
    "foo",
    "Ur",
) # noqa: UP015
```

Needs to be rewritten to 

```py
open(
    "foo",
    "Ur", # noqa: UP015
)
```

There have been now new issues or PRs since the new preview behavior was
implemented. It first was released as part of Ruff 0.9.5 on the 5th of
Feb (a little more than a month ago)

## Test Plan

I reviewed the snapshot tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics Related to reporting of diagnostics. preview Related to preview mode features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UP015's range and message are slightly incorrect

2 participants