Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pyupgrade] Implement import-replacement rule (UP035) #2049

Merged
merged 50 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
cf9155f
Basic groundwork laid
colin99d Jan 20, 2023
6b5c4aa
Going to WIPE libcst
colin99d Jan 21, 2023
04ac882
Fixed conversion
colin99d Jan 21, 2023
9ac1642
Need to switch
colin99d Jan 21, 2023
34b28fc
Merged
colin99d Jan 21, 2023
ac38462
Better indentation tests
colin99d Jan 21, 2023
1c1d391
Fixed second from indentation issue
colin99d Jan 21, 2023
7035102
Fixed fmt and nightly
colin99d Jan 21, 2023
51f6d5c
Added a bunch more things to replace
colin99d Jan 21, 2023
1980519
Added some fixes
colin99d Jan 21, 2023
1fbd14c
Fixed a bug in formatting
colin99d Jan 21, 2023
b7016fa
Fixed formatting error
colin99d Jan 21, 2023
0448418
Fixed formatting errors
colin99d Jan 21, 2023
3bf08dd
Got base tests going
colin99d Jan 21, 2023
b0d2456
Got the mods in
colin99d Jan 21, 2023
860a1d1
Finished up a rough draft, still has the libcst bug
colin99d Jan 21, 2023
4a8263a
Fixed some formatting
colin99d Jan 21, 2023
08c2174
Fixed clippy
colin99d Jan 21, 2023
8e98545
Merge branch 'main' into ImportReplacements
colin99d Jan 22, 2023
6b4d68a
STARTED TRANSITION FROM LIBCST TO CUSTOM
colin99d Jan 22, 2023
30a7180
An MVP with no known bugs
colin99d Jan 22, 2023
f811a84
Added more tests for six.moves
colin99d Jan 22, 2023
b326a29
Handled one last issue
colin99d Jan 22, 2023
af1af04
Fixed some more stuff
colin99d Jan 22, 2023
e8a55a7
Added some fixes
colin99d Jan 22, 2023
679a134
Fixed clippy
colin99d Jan 22, 2023
fd8f418
Deleted unused snapshots
colin99d Jan 22, 2023
ac95e2c
Fixed typos
colin99d Jan 22, 2023
e9bd812
Fixed typos
colin99d Jan 22, 2023
943585c
Added some tests
colin99d Jan 23, 2023
42ae4c5
Fixed tests
colin99d Jan 23, 2023
50c85ac
Merge branch 'main' into ImportReplacements
colin99d Jan 26, 2023
04cd251
Recommended changes
colin99d Jan 26, 2023
65cc26a
Merge branch 'main' into ImportReplacements
colin99d Jan 27, 2023
9d67f07
Merge branch 'main' into ImportReplacements
charliermarsh Jan 29, 2023
603c10b
Rewrite parts of the check
charliermarsh Jan 30, 2023
f7cbd58
Removed six stuff
colin99d Jan 30, 2023
880ebca
Merge branch 'ImportReplacements' of https://github.com/colin99d/ruff…
colin99d Jan 30, 2023
91c38b6
Merge branch 'main' into ImportReplacements
colin99d Jan 30, 2023
0c0a098
removed six
colin99d Jan 30, 2023
3d820f0
Merge branch 'ImportReplacements' of https://github.com/colin99d/ruff…
colin99d Jan 30, 2023
fd53580
Merge branch 'main' into ImportReplacements
charliermarsh Jan 30, 2023
c071895
Merge branch 'charlie/import-replacements' into ImportReplacements
charliermarsh Jan 30, 2023
ef4d532
Small refactors; add one failing test
charliermarsh Jan 30, 2023
2af94db
Avoid bad multi-line fix
charliermarsh Jan 30, 2023
cd7ea96
Merge branch 'main' into ImportReplacements
charliermarsh Jan 30, 2023
1cb84fc
Always flag
charliermarsh Jan 30, 2023
53d6b1f
Flag multi
charliermarsh Jan 30, 2023
dad535f
Use pyupgrade-like token based removal
charliermarsh Jan 30, 2023
f17c2ff
Merge branch 'main' into ImportReplacements
charliermarsh Jan 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
removed six
  • Loading branch information
colin99d committed Jan 30, 2023
commit 0c0a09894059d3b7665e9924d79f44ef345dc194
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,6 @@ For more, see [pyupgrade](https://pypi.org/project/pyupgrade/) on PyPI.
| UP013 | convert-typed-dict-functional-to-class | Convert `{name}` from `TypedDict` functional to class syntax | 🛠 |
| UP014 | convert-named-tuple-functional-to-class | Convert `{name}` from `NamedTuple` functional to class syntax | 🛠 |
| UP015 | redundant-open-modes | Unnecessary open mode parameters | 🛠 |
| UP016 | remove-six-compat | Unnecessary `six` compatibility usage | 🛠 |
| UP017 | datetime-timezone-utc | Use `datetime.UTC` alias | 🛠 |
| UP018 | native-literals | Unnecessary call to `{literal_type}` | 🛠 |
| UP019 | typing-text-str-alias | `typing.Text` is deprecated, use `str` | 🛠 |
Expand All @@ -814,7 +813,6 @@ For more, see [pyupgrade](https://pypi.org/project/pyupgrade/) on PyPI.
| UP033 | functools-cache | Use `@functools.cache` instead of `@functools.lru_cache(maxsize=None)` | 🛠 |
| UP034 | extraneous-parentheses | Avoid extraneous parentheses | 🛠 |
| UP035 | import-replacements | Replace old formatting imports with their new versions | 🛠 |
| UP036 | import-replacements-six | Replace old formatting imports with their new versions | 🛠 |

### flake8-2020 (YTT)

Expand Down
87 changes: 0 additions & 87 deletions resources/test/fixtures/pyupgrade/UP016.py

This file was deleted.

2 changes: 0 additions & 2 deletions resources/test/fixtures/pyupgrade/UP035.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

from collections import Counter, Mapping, Sequence

from six.moves import getcwd, StringIO

from collections import Mapping as mapping, Counter

if True:
Expand Down
31 changes: 0 additions & 31 deletions resources/test/fixtures/pyupgrade/UP036.py

This file was deleted.

2 changes: 0 additions & 2 deletions ruff.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,6 @@
"UP013",
"UP014",
"UP015",
"UP016",
"UP017",
"UP018",
"UP019",
Expand All @@ -1892,7 +1891,6 @@
"UP033",
"UP034",
"UP035",
"UP036",
"W",
"W2",
"W29",
Expand Down
49 changes: 0 additions & 49 deletions src/rules/pyupgrade/rules/import_replacements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ impl AlwaysAutofixableViolation for ImportReplacements {
const BAD_MODULES: &[&str] = &[
"collections",
"pipes",
"six",
"six.moves",
"six.moves.urllib",
"mypy_extensions",
"typing_extensions",
"typing",
Expand Down Expand Up @@ -66,24 +63,6 @@ const COLLECTIONS_TO_ABC: &[&str] = &[

const PIPES_TO_SHLEX: &[&str] = &["quote"];

const SIX_TO_IO: &[&str] = &["BytesIO", "StringIO"];

const SIX_TO_FUNCTOOLS: &[&str] = &["wraps"];

const SIXMOVES_TO_IO: &[&str] = &["StringIO"];

const SIXMOVES_TO_COLLECTIONS: &[&str] = &["UserDict", "UserList", "UserString"];

const SIXMOVES_TO_ITERTOOLS: &[&str] = &["filterfalse", "zip_longest"];

const SIXMOVES_TO_OS: &[&str] = &["getcwd", "getcwdb"];

const SIXMOVES_TO_SUBPROCESS: &[&str] = &["getouput"];

const SIXMOVES_TO_SYS: &[&str] = &["intern"];

const SIXMOVES_TO_URLLIB: &[&str] = &["parse", "request", "response", "error", "robotparser"];

const TYPINGEXTENSIONS_TO_TYPING: &[&str] = &[
"AsyncIterable",
"AsyncIterator",
Expand Down Expand Up @@ -243,34 +222,6 @@ impl<'a> FixImports<'a> {
match self.module {
"collections" => self.create_new_str(COLLECTIONS_TO_ABC, "collections.abc"),
"pipes" => self.create_new_str(PIPES_TO_SHLEX, "shlex"),
"six" => {
if has_match(SIX_TO_IO, self.names) {
self.create_new_str(SIX_TO_IO, "io")
} else if has_match(SIX_TO_FUNCTOOLS, self.names) {
self.create_new_str(SIX_TO_FUNCTOOLS, "functools")
} else {
None
}
}
"six.moves" => {
if has_match(SIXMOVES_TO_IO, self.names) {
self.create_new_str(SIXMOVES_TO_IO, "io")
} else if has_match(SIXMOVES_TO_COLLECTIONS, self.names) {
self.create_new_str(SIXMOVES_TO_COLLECTIONS, "collections")
} else if has_match(SIXMOVES_TO_ITERTOOLS, self.names) {
self.create_new_str(SIXMOVES_TO_ITERTOOLS, "itertools")
} else if has_match(SIXMOVES_TO_OS, self.names) {
self.create_new_str(SIXMOVES_TO_OS, "os")
} else if has_match(SIXMOVES_TO_SUBPROCESS, self.names) {
self.create_new_str(SIXMOVES_TO_SUBPROCESS, "subprocess")
} else if has_match(SIXMOVES_TO_SYS, self.names) {
self.create_new_str(SIXMOVES_TO_SYS, "sys")
} else if has_match(SIXMOVES_TO_URLLIB, self.names) {
self.create_new_str(SIXMOVES_TO_URLLIB, "urllib")
} else {
None
}
}
"typing_extensions" => {
if has_match(TYPINGEXTENSIONS_TO_TYPING, self.names) {
self.create_new_str(TYPINGEXTENSIONS_TO_TYPING, "typing")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,119 +166,100 @@ expression: diagnostics
column: 0
end_location:
row: 20
column: 38
fix:
content:
- from six.moves import getcwd
- from io import StringIO
location:
row: 20
column: 0
end_location:
row: 20
column: 38
parent: ~
- kind:
ImportReplacements: ~
location:
row: 22
column: 0
end_location:
row: 22
column: 51
fix:
content:
- from collections import Counter
- from collections.abc import Mapping as mapping
location:
row: 22
row: 20
column: 0
end_location:
row: 22
row: 20
column: 51
parent: ~
- kind:
ImportReplacements: ~
location:
row: 25
row: 23
column: 4
end_location:
row: 25
row: 23
column: 44
fix:
content:
- from collections import Counter
- " from collections.abc import Mapping"
location:
row: 25
row: 23
column: 4
end_location:
row: 25
row: 23
column: 44
parent: ~
- kind:
ImportReplacements: ~
location:
row: 30
row: 28
column: 4
end_location:
row: 30
row: 28
column: 44
fix:
content:
- from collections import Counter
- " from collections.abc import Mapping"
location:
row: 30
row: 28
column: 4
end_location:
row: 30
row: 28
column: 44
parent: ~
- kind:
ImportReplacements: ~
location:
row: 32
row: 30
column: 9
end_location:
row: 32
row: 30
column: 40
fix:
content:
- from collections.abc import Mapping
location:
row: 32
row: 30
column: 9
end_location:
row: 32
row: 30
column: 40
parent: ~
- kind:
ImportReplacements: ~
location:
row: 35
row: 33
column: 0
end_location:
row: 35
row: 33
column: 40
fix:
content:
- from collections import Counter
- from collections.abc import Mapping
location:
row: 35
row: 33
column: 0
end_location:
row: 35
row: 33
column: 40
parent: ~
- kind:
ImportReplacements: ~
location:
row: 39
row: 37
column: 4
end_location:
row: 44
row: 42
column: 5
fix:
content:
Expand All @@ -291,10 +272,10 @@ expression: diagnostics
- " Callable"
- " )"
location:
row: 39
row: 37
column: 4
end_location:
row: 44
row: 42
column: 5
parent: ~