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 stuff
  • Loading branch information
colin99d committed Jan 30, 2023
commit f7cbd580b32df9648ac8a9d1a6a3b847dc0f8440
10 changes: 0 additions & 10 deletions src/checkers/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,9 +1069,6 @@ where
if self.settings.rules.enabled(&Rule::ImportReplacements) {
pyupgrade::rules::import_replacements(self, stmt, names, module);
}
if self.settings.rules.enabled(&Rule::ImportReplacementsSix) {
pyupgrade::rules::import_replacements_six(self, stmt, module, names);
}
if self.settings.rules.enabled(&Rule::UnnecessaryBuiltinImport) {
if let Some(module) = module.as_deref() {
pyupgrade::rules::unnecessary_builtin_import(self, stmt, module, names);
Expand Down Expand Up @@ -2092,10 +2089,6 @@ where
pyupgrade::rules::use_pep585_annotation(self, expr);
}

if self.settings.rules.enabled(&Rule::RemoveSixCompat) {
pyupgrade::rules::remove_six_compat(self, expr);
}

if self.settings.rules.enabled(&Rule::DatetimeTimezoneUTC)
&& self.settings.target_version >= PythonVersion::Py311
{
Expand Down Expand Up @@ -2229,9 +2222,6 @@ where
if self.settings.rules.enabled(&Rule::RedundantOpenModes) {
pyupgrade::rules::redundant_open_modes(self, expr);
}
if self.settings.rules.enabled(&Rule::RemoveSixCompat) {
pyupgrade::rules::remove_six_compat(self, expr);
}
if self.settings.rules.enabled(&Rule::NativeLiterals) {
pyupgrade::rules::native_literals(self, expr, func, args, keywords);
}
Expand Down
2 changes: 0 additions & 2 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ ruff_macros::define_rule_mapping!(
UP013 => violations::ConvertTypedDictFunctionalToClass,
UP014 => violations::ConvertNamedTupleFunctionalToClass,
UP015 => violations::RedundantOpenModes,
UP016 => violations::RemoveSixCompat,
UP017 => violations::DatetimeTimezoneUTC,
UP018 => violations::NativeLiterals,
UP019 => violations::TypingTextStrAlias,
Expand All @@ -257,7 +256,6 @@ ruff_macros::define_rule_mapping!(
UP033 => violations::FunctoolsCache,
UP034 => violations::ExtraneousParentheses,
UP035 => rules::pyupgrade::rules::ImportReplacements,
UP036 => rules::pyupgrade::rules::ImportReplacementsSix,
// pydocstyle
D100 => violations::PublicModule,
D101 => violations::PublicClass,
Expand Down
2 changes: 0 additions & 2 deletions src/rules/pyupgrade/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ mod tests {
#[test_case(Rule::ConvertTypedDictFunctionalToClass, Path::new("UP013.py"); "UP013")]
#[test_case(Rule::ConvertNamedTupleFunctionalToClass, Path::new("UP014.py"); "UP014")]
#[test_case(Rule::RedundantOpenModes, Path::new("UP015.py"); "UP015")]
#[test_case(Rule::RemoveSixCompat, Path::new("UP016.py"); "UP016")]
#[test_case(Rule::NativeLiterals, Path::new("UP018.py"); "UP018")]
#[test_case(Rule::TypingTextStrAlias, Path::new("UP019.py"); "UP019")]
#[test_case(Rule::ReplaceUniversalNewlines, Path::new("UP021.py"); "UP021")]
Expand All @@ -59,7 +58,6 @@ mod tests {
#[test_case(Rule::FunctoolsCache, Path::new("UP033.py"); "UP033")]
#[test_case(Rule::ExtraneousParentheses, Path::new("UP034.py"); "UP034")]
#[test_case(Rule::ImportReplacements, Path::new("UP035.py"); "UP035")]
#[test_case(Rule::ImportReplacementsSix, Path::new("UP036.py"); "UP036")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let diagnostics = test_path(
Expand Down
211 changes: 0 additions & 211 deletions src/rules/pyupgrade/rules/import_replacements_six.rs

This file was deleted.

4 changes: 0 additions & 4 deletions src/rules/pyupgrade/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub(crate) use f_strings::f_strings;
pub(crate) use format_literals::format_literals;
pub(crate) use functools_cache::functools_cache;
pub(crate) use import_replacements::{import_replacements, ImportReplacements};
pub(crate) use import_replacements_six::{import_replacements_six, ImportReplacementsSix};
pub(crate) use lru_cache_without_parameters::lru_cache_without_parameters;
pub(crate) use native_literals::native_literals;
use once_cell::sync::Lazy;
Expand All @@ -16,7 +15,6 @@ pub(crate) use os_error_alias::os_error_alias;
pub(crate) use printf_string_formatting::printf_string_formatting;
pub(crate) use redundant_open_modes::redundant_open_modes;
use regex::Regex;
pub(crate) use remove_six_compat::remove_six_compat;
pub(crate) use replace_stdout_stderr::replace_stdout_stderr;
pub(crate) use replace_universal_newlines::replace_universal_newlines;
pub(crate) use rewrite_c_element_tree::replace_c_element_tree;
Expand Down Expand Up @@ -52,14 +50,12 @@ mod f_strings;
mod format_literals;
mod functools_cache;
mod import_replacements;
mod import_replacements_six;
mod lru_cache_without_parameters;
mod native_literals;
mod open_alias;
mod os_error_alias;
mod printf_string_formatting;
mod redundant_open_modes;
mod remove_six_compat;
mod replace_stdout_stderr;
mod replace_universal_newlines;
mod rewrite_c_element_tree;
Expand Down
Loading