diff --git a/README.md b/README.md index 98ab0e9439..8a7e943214 100644 --- a/README.md +++ b/README.md @@ -437,7 +437,6 @@ For more, see [pyupgrade](https://pypi.org/project/pyupgrade/3.2.0/) on PyPI. | Code | Name | Message | Fix | | ---- | ---- | ------- | --- | | U001 | UselessMetaclassType | `__metaclass__ = type` is implied | 🛠 | -| U002 | UnnecessaryAbspath | `abspath(__file__)` is unnecessary in Python 3.9 and later | 🛠 | | U003 | TypeOfPrimitive | Use `str` instead of `type(...)` | 🛠 | | U004 | UselessObjectInheritance | Class `...` inherits from object | 🛠 | | U005 | DeprecatedUnittestAlias | `assertEquals` is deprecated, use `assertEqual` instead | 🛠 | @@ -712,7 +711,7 @@ including: - [`flake8-bandit`](https://pypi.org/project/flake8-bandit/) (6/40) - [`flake8-bugbear`](https://pypi.org/project/flake8-bugbear/) (25/32) - [`flake8-2020`](https://pypi.org/project/flake8-2020/) -- [`pyupgrade`](https://pypi.org/project/pyupgrade/) (15/34) +- [`pyupgrade`](https://pypi.org/project/pyupgrade/) (14/33) - [`autoflake`](https://pypi.org/project/autoflake/) (1/7) Beyond rule-set parity, Ruff suffers from the following limitations vis-à-vis Flake8: @@ -739,7 +738,7 @@ Today, Ruff can be used to replace Flake8 when used with any of the following pl - [`flake8-2020`](https://pypi.org/project/flake8-2020/) Ruff can also replace [`isort`](https://pypi.org/project/isort/), [`yesqa`](https://github.com/asottile/yesqa), -and a subset of the rules implemented in [`pyupgrade`](https://pypi.org/project/pyupgrade/) (15/34). +and a subset of the rules implemented in [`pyupgrade`](https://pypi.org/project/pyupgrade/) (14/33). If you're looking to use Ruff, but rely on an unsupported Flake8 plugin, free to file an Issue. diff --git a/resources/test/fixtures/U002.py b/resources/test/fixtures/U002.py deleted file mode 100644 index 0a85ac0828..0000000000 --- a/resources/test/fixtures/U002.py +++ /dev/null @@ -1,15 +0,0 @@ -from os.path import abspath - -x = abspath(__file__) - - -import os - - -y = os.path.abspath(__file__) - - -from os import path - - -z = path.abspath(__file__) diff --git a/src/check_ast.rs b/src/check_ast.rs index e2d7172532..1aee834fa9 100644 --- a/src/check_ast.rs +++ b/src/check_ast.rs @@ -1435,12 +1435,6 @@ where } // pyupgrade - if self.settings.enabled.contains(&CheckCode::U002) - && self.settings.target_version >= PythonVersion::Py310 - { - pyupgrade::plugins::unnecessary_abspath(self, expr, func, args); - } - if self.settings.enabled.contains(&CheckCode::U003) { pyupgrade::plugins::type_of_primitive(self, expr, func, args); } diff --git a/src/checks.rs b/src/checks.rs index 417bff168a..7e20962b08 100644 --- a/src/checks.rs +++ b/src/checks.rs @@ -152,7 +152,6 @@ pub enum CheckCode { YTT303, // pyupgrade U001, - U002, U003, U004, U005, @@ -457,7 +456,6 @@ pub enum CheckKind { SysVersionSlice1Referenced, // pyupgrade TypeOfPrimitive(Primitive), - UnnecessaryAbspath, UselessMetaclassType, DeprecatedUnittestAlias(String, String), UselessObjectInheritance(String), @@ -717,7 +715,6 @@ impl CheckCode { CheckCode::YTT303 => CheckKind::SysVersionSlice1Referenced, // pyupgrade CheckCode::U001 => CheckKind::UselessMetaclassType, - CheckCode::U002 => CheckKind::UnnecessaryAbspath, CheckCode::U003 => CheckKind::TypeOfPrimitive(Primitive::Str), CheckCode::U004 => CheckKind::UselessObjectInheritance("...".to_string()), CheckCode::U005 => CheckKind::DeprecatedUnittestAlias( @@ -944,7 +941,6 @@ impl CheckCode { CheckCode::YTT302 => CheckCategory::Flake82020, CheckCode::YTT303 => CheckCategory::Flake82020, CheckCode::U001 => CheckCategory::Pyupgrade, - CheckCode::U002 => CheckCategory::Pyupgrade, CheckCode::U003 => CheckCategory::Pyupgrade, CheckCode::U004 => CheckCategory::Pyupgrade, CheckCode::U005 => CheckCategory::Pyupgrade, @@ -1159,7 +1155,6 @@ impl CheckKind { CheckKind::SysVersionSlice1Referenced => &CheckCode::YTT303, // pyupgrade CheckKind::TypeOfPrimitive(_) => &CheckCode::U003, - CheckKind::UnnecessaryAbspath => &CheckCode::U002, CheckKind::UselessMetaclassType => &CheckCode::U001, CheckKind::DeprecatedUnittestAlias(..) => &CheckCode::U005, CheckKind::UsePEP585Annotation(_) => &CheckCode::U006, @@ -1674,9 +1669,6 @@ impl CheckKind { CheckKind::TypeOfPrimitive(primitive) => { format!("Use `{}` instead of `type(...)`", primitive.builtin()) } - CheckKind::UnnecessaryAbspath => { - "`abspath(__file__)` is unnecessary in Python 3.9 and later".to_string() - } CheckKind::UselessMetaclassType => "`__metaclass__ = type` is implied".to_string(), CheckKind::DeprecatedUnittestAlias(alias, target) => { format!("`{alias}` is deprecated, use `{target}` instead") @@ -1986,7 +1978,6 @@ impl CheckKind { | CheckKind::SectionUnderlineNotOverIndented(_) | CheckKind::SuperCallWithParameters | CheckKind::TypeOfPrimitive(_) - | CheckKind::UnnecessaryAbspath | CheckKind::UnnecessaryCollectionCall(_) | CheckKind::UnnecessaryComprehension(_) | CheckKind::UnnecessaryEncodeUTF8 diff --git a/src/checks_gen.rs b/src/checks_gen.rs index dce9105915..b423fab737 100644 --- a/src/checks_gen.rs +++ b/src/checks_gen.rs @@ -269,7 +269,6 @@ pub enum CheckCodePrefix { U0, U00, U001, - U002, U003, U004, U005, @@ -1067,7 +1066,6 @@ impl CheckCodePrefix { CheckCodePrefix::T203 => vec![CheckCode::T203], CheckCodePrefix::U => vec![ CheckCode::U001, - CheckCode::U002, CheckCode::U003, CheckCode::U004, CheckCode::U005, @@ -1081,7 +1079,6 @@ impl CheckCodePrefix { ], CheckCodePrefix::U0 => vec![ CheckCode::U001, - CheckCode::U002, CheckCode::U003, CheckCode::U004, CheckCode::U005, @@ -1095,7 +1092,6 @@ impl CheckCodePrefix { ], CheckCodePrefix::U00 => vec![ CheckCode::U001, - CheckCode::U002, CheckCode::U003, CheckCode::U004, CheckCode::U005, @@ -1105,7 +1101,6 @@ impl CheckCodePrefix { CheckCode::U009, ], CheckCodePrefix::U001 => vec![CheckCode::U001], - CheckCodePrefix::U002 => vec![CheckCode::U002], CheckCodePrefix::U003 => vec![CheckCode::U003], CheckCodePrefix::U004 => vec![CheckCode::U004], CheckCodePrefix::U005 => vec![CheckCode::U005], @@ -1431,7 +1426,6 @@ impl CheckCodePrefix { CheckCodePrefix::U0 => PrefixSpecificity::Hundreds, CheckCodePrefix::U00 => PrefixSpecificity::Tens, CheckCodePrefix::U001 => PrefixSpecificity::Explicit, - CheckCodePrefix::U002 => PrefixSpecificity::Explicit, CheckCodePrefix::U003 => PrefixSpecificity::Explicit, CheckCodePrefix::U004 => PrefixSpecificity::Explicit, CheckCodePrefix::U005 => PrefixSpecificity::Explicit, diff --git a/src/linter.rs b/src/linter.rs index cb8bea5839..1634c8f511 100644 --- a/src/linter.rs +++ b/src/linter.rs @@ -487,7 +487,6 @@ mod tests { #[test_case(CheckCode::T201, Path::new("T201.py"); "T201")] #[test_case(CheckCode::T203, Path::new("T203.py"); "T203")] #[test_case(CheckCode::U001, Path::new("U001.py"); "U001")] - #[test_case(CheckCode::U002, Path::new("U002.py"); "U002")] #[test_case(CheckCode::U003, Path::new("U003.py"); "U003")] #[test_case(CheckCode::U004, Path::new("U004.py"); "U004")] #[test_case(CheckCode::U005, Path::new("U005.py"); "U005")] diff --git a/src/pyupgrade/checks.rs b/src/pyupgrade/checks.rs index 3c5967b796..f9d80b0e67 100644 --- a/src/pyupgrade/checks.rs +++ b/src/pyupgrade/checks.rs @@ -90,26 +90,6 @@ pub fn useless_metaclass_type(targets: &[Expr], value: &Expr, location: Range) - None } -/// U002 -pub fn unnecessary_abspath(func: &Expr, args: &[Expr], location: Range) -> Option { - // Validate the arguments. - if args.len() == 1 { - if let ExprKind::Name { id, .. } = &args[0].node { - if id == "__file__" { - match &func.node { - ExprKind::Attribute { attr: id, .. } | ExprKind::Name { id, .. } => { - if id == "abspath" { - return Some(Check::new(CheckKind::UnnecessaryAbspath, location)); - } - } - _ => {} - } - } - } - } - None -} - /// U004 pub fn useless_object_inheritance(name: &str, bases: &[Expr], scope: &Scope) -> Option { for expr in bases { diff --git a/src/pyupgrade/plugins/mod.rs b/src/pyupgrade/plugins/mod.rs index 4b6a2eda95..a22e0744a4 100644 --- a/src/pyupgrade/plugins/mod.rs +++ b/src/pyupgrade/plugins/mod.rs @@ -1,7 +1,6 @@ pub use deprecated_unittest_alias::deprecated_unittest_alias; pub use super_call_with_parameters::super_call_with_parameters; pub use type_of_primitive::type_of_primitive; -pub use unnecessary_abspath::unnecessary_abspath; pub use unnecessary_encode_utf8::unnecessary_encode_utf8; pub use unnecessary_future_import::unnecessary_future_import; pub use unnecessary_lru_cache_params::unnecessary_lru_cache_params; @@ -13,7 +12,6 @@ pub use useless_object_inheritance::useless_object_inheritance; mod deprecated_unittest_alias; mod super_call_with_parameters; mod type_of_primitive; -mod unnecessary_abspath; mod unnecessary_encode_utf8; mod unnecessary_future_import; mod unnecessary_lru_cache_params; diff --git a/src/pyupgrade/plugins/unnecessary_abspath.rs b/src/pyupgrade/plugins/unnecessary_abspath.rs deleted file mode 100644 index d2851bcc30..0000000000 --- a/src/pyupgrade/plugins/unnecessary_abspath.rs +++ /dev/null @@ -1,20 +0,0 @@ -use rustpython_ast::Expr; - -use crate::ast::types::Range; -use crate::autofix::Fix; -use crate::check_ast::Checker; -use crate::pyupgrade::checks; - -/// U002 -pub fn unnecessary_abspath(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) { - if let Some(mut check) = checks::unnecessary_abspath(func, args, Range::from_located(expr)) { - if checker.patch() { - check.amend(Fix::replacement( - "__file__".to_string(), - expr.location, - expr.end_location.unwrap(), - )); - } - checker.add_check(check); - } -} diff --git a/src/snapshots/ruff__linter__tests__U002_U002.py.snap b/src/snapshots/ruff__linter__tests__U002_U002.py.snap deleted file mode 100644 index ec227da7f1..0000000000 --- a/src/snapshots/ruff__linter__tests__U002_U002.py.snap +++ /dev/null @@ -1,56 +0,0 @@ ---- -source: src/linter.rs -expression: checks ---- -- kind: UnnecessaryAbspath - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 21 - fix: - patch: - content: __file__ - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 21 - applied: false -- kind: UnnecessaryAbspath - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 29 - fix: - patch: - content: __file__ - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 29 - applied: false -- kind: UnnecessaryAbspath - location: - row: 15 - column: 4 - end_location: - row: 15 - column: 26 - fix: - patch: - content: __file__ - location: - row: 15 - column: 4 - end_location: - row: 15 - column: 26 - applied: false -