-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly handle references in
__all__
definitions when renaming sy…
…mbols in autofixes
- Loading branch information
1 parent
487ae5f
commit c85be69
Showing
11 changed files
with
139 additions
and
7 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI025_2.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
"""Tests to ensure we correctly rename references inside `__all__`""" | ||
|
||
from collections.abc import Set | ||
|
||
__all__ = ["Set"] | ||
|
||
if True: | ||
__all__ += [r'''Set'''] | ||
|
||
if 1: | ||
__all__ += ["S" "e" "t"] |
8 changes: 8 additions & 0 deletions
8
crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI025_2.pyi
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
"""Tests to ensure we correctly rename references inside `__all__`""" | ||
|
||
from collections.abc import Set | ||
|
||
__all__ = ["Set"] | ||
|
||
if True: | ||
__all__ += [r'''Set'''] | ||
|
||
if 1: | ||
__all__ += ["S" "e" "t"] |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
30 changes: 30 additions & 0 deletions
30
...rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI025_PYI025_2.py.snap
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_pyi/mod.rs | ||
--- | ||
PYI025_2.py:3:29: PYI025 [*] Use `from collections.abc import Set as AbstractSet` to avoid confusion with the `set` builtin | ||
| | ||
1 | """Tests to ensure we correctly rename references inside `__all__`""" | ||
2 | | ||
3 | from collections.abc import Set | ||
| ^^^ PYI025 | ||
4 | | ||
5 | __all__ = ["Set"] | ||
| | ||
= help: Alias `Set` to `AbstractSet` | ||
|
||
ℹ Unsafe fix | ||
1 1 | """Tests to ensure we correctly rename references inside `__all__`""" | ||
2 2 | | ||
3 |-from collections.abc import Set | ||
3 |+from collections.abc import Set as AbstractSet | ||
4 4 | | ||
5 |-__all__ = ["Set"] | ||
5 |+__all__ = ["AbstractSet"] | ||
6 6 | | ||
7 7 | if True: | ||
8 |- __all__ += [r'''Set'''] | ||
8 |+ __all__ += [r'''AbstractSet'''] | ||
9 9 | | ||
10 10 | if 1: | ||
11 |- __all__ += ["S" "e" "t"] | ||
11 |+ __all__ += ["AbstractSet"] |
30 changes: 30 additions & 0 deletions
30
...ules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI025_PYI025_2.pyi.snap
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_pyi/mod.rs | ||
--- | ||
PYI025_2.pyi:3:29: PYI025 [*] Use `from collections.abc import Set as AbstractSet` to avoid confusion with the `set` builtin | ||
| | ||
1 | """Tests to ensure we correctly rename references inside `__all__`""" | ||
2 | | ||
3 | from collections.abc import Set | ||
| ^^^ PYI025 | ||
4 | | ||
5 | __all__ = ["Set"] | ||
| | ||
= help: Alias `Set` to `AbstractSet` | ||
|
||
ℹ Unsafe fix | ||
1 1 | """Tests to ensure we correctly rename references inside `__all__`""" | ||
2 2 | | ||
3 |-from collections.abc import Set | ||
3 |+from collections.abc import Set as AbstractSet | ||
4 4 | | ||
5 |-__all__ = ["Set"] | ||
5 |+__all__ = ["AbstractSet"] | ||
6 6 | | ||
7 7 | if True: | ||
8 |- __all__ += [r'''Set'''] | ||
8 |+ __all__ += [r'''AbstractSet'''] | ||
9 9 | | ||
10 10 | if 1: | ||
11 |- __all__ += ["S" "e" "t"] | ||
11 |+ __all__ += ["AbstractSet"] |
This file contains 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
This file contains 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
This file contains 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