diff --git a/crates/ruff/src/rules/flake8_bugbear/mod.rs b/crates/ruff/src/rules/flake8_bugbear/mod.rs index 005fe03002145..50edabed6d838 100644 --- a/crates/ruff/src/rules/flake8_bugbear/mod.rs +++ b/crates/ruff/src/rules/flake8_bugbear/mod.rs @@ -11,6 +11,7 @@ mod tests { use crate::assert_messages; use crate::registry::Rule; + use crate::settings::types::PythonVersion; use crate::settings::Settings; use crate::test::test_path; @@ -49,7 +50,6 @@ mod tests { #[test_case(Rule::UselessComparison, Path::new("B015.py"))] #[test_case(Rule::UselessContextlibSuppress, Path::new("B022.py"))] #[test_case(Rule::UselessExpression, Path::new("B018.py"))] - #[test_case(Rule::ZipWithoutExplicitStrict, Path::new("B905.py"))] fn rules(rule_code: Rule, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( @@ -60,6 +60,18 @@ mod tests { Ok(()) } + #[test] + fn zip_without_explicit_strict() -> Result<()> { + let snapshot = "B905.py"; + let diagnostics = test_path( + Path::new("flake8_bugbear").join(snapshot).as_path(), + &Settings::for_rule(Rule::ZipWithoutExplicitStrict) + .with_target_version(PythonVersion::latest()), + )?; + assert_messages!(snapshot, diagnostics); + Ok(()) + } + #[test] fn extend_immutable_calls() -> Result<()> { let snapshot = "extend_immutable_calls".to_string(); diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B905_B905.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B905.py.snap similarity index 100% rename from crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B905_B905.py.snap rename to crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B905.py.snap diff --git a/crates/ruff/src/rules/flake8_use_pathlib/mod.rs b/crates/ruff/src/rules/flake8_use_pathlib/mod.rs index b319fd92ee24d..39a0bd7bbdeea 100644 --- a/crates/ruff/src/rules/flake8_use_pathlib/mod.rs +++ b/crates/ruff/src/rules/flake8_use_pathlib/mod.rs @@ -12,6 +12,7 @@ mod tests { use crate::assert_messages; use crate::registry::Rule; use crate::settings; + use crate::settings::types::PythonVersion; use crate::test::test_path; #[test_case(Path::new("full_name.py"))] @@ -48,7 +49,8 @@ mod tests { Rule::OsPathSamefile, Rule::OsPathSplitext, Rule::BuiltinOpen, - ]), + ]) + .with_target_version(PythonVersion::latest()), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -67,7 +69,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_use_pathlib").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff/src/rules/pylint/mod.rs b/crates/ruff/src/rules/pylint/mod.rs index fbe0c1abe31d9..6f127f394de4c 100644 --- a/crates/ruff/src/rules/pylint/mod.rs +++ b/crates/ruff/src/rules/pylint/mod.rs @@ -130,7 +130,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("pylint").join(path).as_path(), - &Settings::for_rules(vec![rule_code]), + &Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -140,10 +140,8 @@ mod tests { fn repeated_isinstance_calls() -> Result<()> { let diagnostics = test_path( Path::new("pylint/repeated_isinstance_calls.py"), - &Settings { - target_version: PythonVersion::Py39, - ..Settings::for_rules(vec![Rule::RepeatedIsinstanceCalls]) - }, + &Settings::for_rule(Rule::RepeatedIsinstanceCalls) + .with_target_version(PythonVersion::Py39), )?; assert_messages!(diagnostics); Ok(()) @@ -153,10 +151,7 @@ mod tests { fn continue_in_finally() -> Result<()> { let diagnostics = test_path( Path::new("pylint/continue_in_finally.py"), - &Settings { - target_version: PythonVersion::Py37, - ..Settings::for_rules(vec![Rule::ContinueInFinally]) - }, + &Settings::for_rule(Rule::ContinueInFinally).with_target_version(PythonVersion::Py37), )?; assert_messages!(diagnostics); Ok(()) @@ -171,7 +166,7 @@ mod tests { allow_magic_value_types: vec![pylint::settings::ConstantType::Int], ..pylint::settings::Settings::default() }, - ..Settings::for_rules(vec![Rule::MagicValueComparison]) + ..Settings::for_rule(Rule::MagicValueComparison) }, )?; assert_messages!(diagnostics); @@ -187,7 +182,7 @@ mod tests { max_args: 4, ..pylint::settings::Settings::default() }, - ..Settings::for_rules(vec![Rule::TooManyArguments]) + ..Settings::for_rule(Rule::TooManyArguments) }, )?; assert_messages!(diagnostics); @@ -200,7 +195,7 @@ mod tests { Path::new("pylint/too_many_arguments_params.py"), &Settings { dummy_variable_rgx: Regex::new(r"skip_.*").unwrap(), - ..Settings::for_rules(vec![Rule::TooManyArguments]) + ..Settings::for_rule(Rule::TooManyArguments) }, )?; assert_messages!(diagnostics); @@ -216,7 +211,7 @@ mod tests { max_branches: 1, ..pylint::settings::Settings::default() }, - ..Settings::for_rules(vec![Rule::TooManyBranches]) + ..Settings::for_rule(Rule::TooManyBranches) }, )?; assert_messages!(diagnostics); @@ -232,7 +227,7 @@ mod tests { max_statements: 1, ..pylint::settings::Settings::default() }, - ..Settings::for_rules(vec![Rule::TooManyStatements]) + ..Settings::for_rule(Rule::TooManyStatements) }, )?; assert_messages!(diagnostics); @@ -248,7 +243,7 @@ mod tests { max_returns: 1, ..pylint::settings::Settings::default() }, - ..Settings::for_rules(vec![Rule::TooManyReturnStatements]) + ..Settings::for_rule(Rule::TooManyReturnStatements) }, )?; assert_messages!(diagnostics); diff --git a/crates/ruff/src/rules/pyupgrade/mod.rs b/crates/ruff/src/rules/pyupgrade/mod.rs index 9e2f633ba03b2..edbec0e5c524a 100644 --- a/crates/ruff/src/rules/pyupgrade/mod.rs +++ b/crates/ruff/src/rules/pyupgrade/mod.rs @@ -81,7 +81,7 @@ mod tests { let snapshot = path.to_string_lossy().to_string(); let diagnostics = test_path( Path::new("pyupgrade").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP035.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP035.py.snap index f610969a3ce86..04319f36dc70b 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP035.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP035.py.snap @@ -974,4 +974,19 @@ UP035.py:76:1: UP035 [*] Import from `collections.abc` instead: `Generator` 78 78 | # OK 79 79 | from a import b +UP035.py:88:1: UP035 [*] Import from `typing` instead: `dataclass_transform` + | +87 | # Ok: `typing_extensions` supports `frozen_default` (backported from 3.12). +88 | from typing_extensions import dataclass_transform + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 + | + = help: Import from `typing` + +ℹ Suggested fix +85 85 | from typing_extensions import NamedTuple +86 86 | +87 87 | # Ok: `typing_extensions` supports `frozen_default` (backported from 3.12). +88 |-from typing_extensions import dataclass_transform + 88 |+from typing import dataclass_transform + diff --git a/crates/ruff/src/rules/ruff/mod.rs b/crates/ruff/src/rules/ruff/mod.rs index 16b6ac7a485fd..1195b3b559996 100644 --- a/crates/ruff/src/rules/ruff/mod.rs +++ b/crates/ruff/src/rules/ruff/mod.rs @@ -44,7 +44,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("ruff").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -60,10 +60,8 @@ mod tests { ); let diagnostics = test_path( Path::new("ruff").join(path).as_path(), - &settings::Settings { - target_version: PythonVersion::Py39, - ..settings::Settings::for_rule(Rule::ImplicitOptional) - }, + &settings::Settings::for_rule(Rule::ImplicitOptional) + .with_target_version(PythonVersion::Py39), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff/src/settings/defaults.rs b/crates/ruff/src/settings/defaults.rs index 6ccc3bf09b9bd..1605c6b02734c 100644 --- a/crates/ruff/src/settings/defaults.rs +++ b/crates/ruff/src/settings/defaults.rs @@ -24,7 +24,7 @@ pub const PREFIXES: &[RuleSelector] = &[ RuleSelector::Linter(Linter::Pyflakes), ]; -pub const TARGET_VERSION: PythonVersion = PythonVersion::Py310; +pub const TARGET_VERSION: PythonVersion = PythonVersion::Py38; pub const TASK_TAGS: &[&str] = &["TODO", "FIXME", "XXX"]; diff --git a/crates/ruff/src/settings/mod.rs b/crates/ruff/src/settings/mod.rs index 3dfc8372cd8c0..efdddd4374f06 100644 --- a/crates/ruff/src/settings/mod.rs +++ b/crates/ruff/src/settings/mod.rs @@ -308,6 +308,13 @@ impl Settings { ..Self::default() } } + + /// Return the [`Settings`] after updating the target [`PythonVersion`]. + #[must_use] + pub fn with_target_version(mut self, target_version: PythonVersion) -> Self { + self.target_version = target_version; + self + } } impl From<&Configuration> for RuleTable { diff --git a/crates/ruff/src/settings/options.rs b/crates/ruff/src/settings/options.rs index 43d3618d77076..7ed6ae20ac4c9 100644 --- a/crates/ruff/src/settings/options.rs +++ b/crates/ruff/src/settings/options.rs @@ -456,7 +456,7 @@ pub struct Options { /// contained an `__init__.py` file. pub namespace_packages: Option>, #[option( - default = r#""py310""#, + default = r#""py38""#, value_type = r#""py37" | "py38" | "py39" | "py310" | "py311" | "py312""#, example = r#" # Always generate Python 3.7-compatible code. diff --git a/crates/ruff/src/settings/types.rs b/crates/ruff/src/settings/types.rs index 82dc6fe34cd01..538918f8dd950 100644 --- a/crates/ruff/src/settings/types.rs +++ b/crates/ruff/src/settings/types.rs @@ -41,6 +41,10 @@ impl From for Pep440Version { } impl PythonVersion { + pub const fn latest() -> Self { + Self::Py312 + } + pub const fn as_tuple(&self) -> (u32, u32) { match self { Self::Py37 => (3, 7),