diff --git a/crates/ruff/src/rules/flake8_bugbear/mod.rs b/crates/ruff/src/rules/flake8_bugbear/mod.rs index 50edabed6d..1d92306633 100644 --- a/crates/ruff/src/rules/flake8_bugbear/mod.rs +++ b/crates/ruff/src/rules/flake8_bugbear/mod.rs @@ -11,7 +11,6 @@ mod tests { use crate::assert_messages; use crate::registry::Rule; - use crate::settings::types::PythonVersion; use crate::settings::Settings; use crate::test::test_path; @@ -65,8 +64,7 @@ mod tests { 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()), + &Settings::for_rule(Rule::ZipWithoutExplicitStrict), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -84,7 +82,7 @@ mod tests { "fastapi.Query".to_string(), ], }, - ..Settings::for_rules(vec![Rule::FunctionCallInDefaultArgument]) + ..Settings::for_rule(Rule::FunctionCallInDefaultArgument) }, )?; assert_messages!(snapshot, diagnostics); diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI050_PYI050.py.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI050_PYI050.py.snap index d1aa2e9116..492243cf19 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI050_PYI050.py.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI050_PYI050.py.snap @@ -1,4 +1,25 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs --- +PYI050.py:13:24: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations + | +13 | def foo_no_return(arg: NoReturn): + | ^^^^^^^^ PYI050 +14 | ... + | + +PYI050.py:23:44: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations + | +23 | def foo_no_return_kwarg(arg: int, *, arg2: NoReturn): + | ^^^^^^^^ PYI050 +24 | ... + | + +PYI050.py:27:47: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations + | +27 | def foo_no_return_pos_only(arg: int, /, arg2: NoReturn): + | ^^^^^^^^ PYI050 +28 | ... + | + diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI050_PYI050.pyi.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI050_PYI050.pyi.snap index f476783f00..2eafac7805 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI050_PYI050.pyi.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI050_PYI050.pyi.snap @@ -1,7 +1,7 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs --- -PYI050.pyi:6:24: PYI050 Prefer `typing_extensions.Never` over `NoReturn` for argument annotations +PYI050.pyi:6:24: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations | 4 | def foo(arg): ... 5 | def foo_int(arg: int): ... @@ -11,7 +11,7 @@ PYI050.pyi:6:24: PYI050 Prefer `typing_extensions.Never` over `NoReturn` for arg 8 | arg: typing_extensions.NoReturn, | -PYI050.pyi:10:44: PYI050 Prefer `typing_extensions.Never` over `NoReturn` for argument annotations +PYI050.pyi:10:44: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations | 8 | arg: typing_extensions.NoReturn, 9 | ): ... # Error: PYI050 @@ -21,7 +21,7 @@ PYI050.pyi:10:44: PYI050 Prefer `typing_extensions.Never` over `NoReturn` for ar 12 | def foo_never(arg: Never): ... | -PYI050.pyi:11:47: PYI050 Prefer `typing_extensions.Never` over `NoReturn` for argument annotations +PYI050.pyi:11:47: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations | 9 | ): ... # Error: PYI050 10 | def foo_no_return_kwarg(arg: int, *, arg2: NoReturn): ... # Error: PYI050 diff --git a/crates/ruff/src/rules/flake8_use_pathlib/mod.rs b/crates/ruff/src/rules/flake8_use_pathlib/mod.rs index 39a0bd7bbd..b319fd92ee 100644 --- a/crates/ruff/src/rules/flake8_use_pathlib/mod.rs +++ b/crates/ruff/src/rules/flake8_use_pathlib/mod.rs @@ -12,7 +12,6 @@ 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"))] @@ -49,8 +48,7 @@ mod tests { Rule::OsPathSamefile, Rule::OsPathSplitext, Rule::BuiltinOpen, - ]) - .with_target_version(PythonVersion::latest()), + ]), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -69,7 +67,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).with_target_version(PythonVersion::latest()), + &settings::Settings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__if_elif_else.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__if_elif_else.py.snap index 514bc775e9..4a9a844881 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__if_elif_else.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__if_elif_else.py.snap @@ -14,9 +14,8 @@ if_elif_else.py:6:1: I001 [*] Import block is un-sorted or un-formatted 3 3 | elif "setuptools" in sys.modules: 4 4 | from setuptools.command.sdist import sdist as _sdist 5 5 | else: -6 |- from setuptools.command.sdist import sdist as _sdist -7 6 | from distutils.command.sdist import sdist as _sdist - 7 |+ - 8 |+ from setuptools.command.sdist import sdist as _sdist + 6 |+ from distutils.command.sdist import sdist as _sdist +6 7 | from setuptools.command.sdist import sdist as _sdist +7 |- from distutils.command.sdist import sdist as _sdist diff --git a/crates/ruff/src/rules/perflint/mod.rs b/crates/ruff/src/rules/perflint/mod.rs index 291bfcd207..3e196d479d 100644 --- a/crates/ruff/src/rules/perflint/mod.rs +++ b/crates/ruff/src/rules/perflint/mod.rs @@ -10,6 +10,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; @@ -22,7 +23,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("perflint").join(path).as_path(), - &Settings::for_rule(rule_code), + &Settings::for_rule(rule_code).with_target_version(PythonVersion::Py310), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff/src/rules/pylint/mod.rs b/crates/ruff/src/rules/pylint/mod.rs index 6f127f394d..fbbb859126 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_rule(rule_code).with_target_version(PythonVersion::latest()), + &Settings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff/src/rules/pyupgrade/mod.rs b/crates/ruff/src/rules/pyupgrade/mod.rs index edbec0e5c5..3e75dc8550 100644 --- a/crates/ruff/src/rules/pyupgrade/mod.rs +++ b/crates/ruff/src/rules/pyupgrade/mod.rs @@ -77,11 +77,12 @@ mod tests { #[test_case(Rule::UselessObjectInheritance, Path::new("UP004.py"))] #[test_case(Rule::YieldInForLoop, Path::new("UP028_0.py"))] #[test_case(Rule::YieldInForLoop, Path::new("UP028_1.py"))] + #[test_case(Rule::NonPEP695TypeAlias, Path::new("UP040.py"))] fn rules(rule_code: Rule, path: &Path) -> Result<()> { 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).with_target_version(PythonVersion::latest()), + &settings::Settings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -100,19 +101,6 @@ mod tests { Ok(()) } - #[test] - fn non_pep695_type_alias_py312() -> Result<()> { - let diagnostics = test_path( - Path::new("pyupgrade/UP040.py"), - &settings::Settings { - target_version: PythonVersion::Py312, - ..settings::Settings::for_rule(Rule::NonPEP695TypeAlias) - }, - )?; - assert_messages!(diagnostics); - Ok(()) - } - #[test] fn future_annotations_keep_runtime_typing_p37() -> Result<()> { let diagnostics = test_path( diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__non_pep695_type_alias_py312.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP040.py.snap similarity index 100% rename from crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__non_pep695_type_alias_py312.snap rename to crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP040.py.snap diff --git a/crates/ruff/src/rules/ruff/mod.rs b/crates/ruff/src/rules/ruff/mod.rs index 1195b3b559..e49a97709e 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).with_target_version(PythonVersion::latest()), + &settings::Settings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff/src/settings/mod.rs b/crates/ruff/src/settings/mod.rs index 51aaed88dd..ffae78aa08 100644 --- a/crates/ruff/src/settings/mod.rs +++ b/crates/ruff/src/settings/mod.rs @@ -298,6 +298,7 @@ impl Settings { pub fn for_rule(rule_code: Rule) -> Self { Self { rules: RuleTable::from_iter([rule_code]), + target_version: PythonVersion::latest(), ..Self::default() } } @@ -305,6 +306,7 @@ impl Settings { pub fn for_rules(rules: impl IntoIterator) -> Self { Self { rules: RuleTable::from_iter(rules), + target_version: PythonVersion::latest(), ..Self::default() } } diff --git a/crates/ruff/src/settings/types.rs b/crates/ruff/src/settings/types.rs index 9e180882e5..8461604425 100644 --- a/crates/ruff/src/settings/types.rs +++ b/crates/ruff/src/settings/types.rs @@ -53,6 +53,7 @@ impl From for Pep440Version { } impl PythonVersion { + /// Return the latest supported Python version. pub const fn latest() -> Self { Self::Py312 }