Skip to content

Commit 6acf07c

Browse files
Use latest Python version by default in tests (#6448)
## Summary Use the same Python version by default for all tests (our latest-supported version). ## Test Plan `cargo test` --------- Co-authored-by: Zanie <[email protected]>
1 parent 38b9fb8 commit 6acf07c

File tree

12 files changed

+40
-32
lines changed

12 files changed

+40
-32
lines changed

crates/ruff/src/rules/flake8_bugbear/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ mod tests {
1111

1212
use crate::assert_messages;
1313
use crate::registry::Rule;
14-
use crate::settings::types::PythonVersion;
1514
use crate::settings::Settings;
1615
use crate::test::test_path;
1716

@@ -65,8 +64,7 @@ mod tests {
6564
let snapshot = "B905.py";
6665
let diagnostics = test_path(
6766
Path::new("flake8_bugbear").join(snapshot).as_path(),
68-
&Settings::for_rule(Rule::ZipWithoutExplicitStrict)
69-
.with_target_version(PythonVersion::latest()),
67+
&Settings::for_rule(Rule::ZipWithoutExplicitStrict),
7068
)?;
7169
assert_messages!(snapshot, diagnostics);
7270
Ok(())
@@ -84,7 +82,7 @@ mod tests {
8482
"fastapi.Query".to_string(),
8583
],
8684
},
87-
..Settings::for_rules(vec![Rule::FunctionCallInDefaultArgument])
85+
..Settings::for_rule(Rule::FunctionCallInDefaultArgument)
8886
},
8987
)?;
9088
assert_messages!(snapshot, diagnostics);
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
11
---
22
source: crates/ruff/src/rules/flake8_pyi/mod.rs
33
---
4+
PYI050.py:13:24: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations
5+
|
6+
13 | def foo_no_return(arg: NoReturn):
7+
| ^^^^^^^^ PYI050
8+
14 | ...
9+
|
10+
11+
PYI050.py:23:44: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations
12+
|
13+
23 | def foo_no_return_kwarg(arg: int, *, arg2: NoReturn):
14+
| ^^^^^^^^ PYI050
15+
24 | ...
16+
|
17+
18+
PYI050.py:27:47: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations
19+
|
20+
27 | def foo_no_return_pos_only(arg: int, /, arg2: NoReturn):
21+
| ^^^^^^^^ PYI050
22+
28 | ...
23+
|
24+
425

crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI050_PYI050.pyi.snap

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
source: crates/ruff/src/rules/flake8_pyi/mod.rs
33
---
4-
PYI050.pyi:6:24: PYI050 Prefer `typing_extensions.Never` over `NoReturn` for argument annotations
4+
PYI050.pyi:6:24: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations
55
|
66
4 | def foo(arg): ...
77
5 | def foo_int(arg: int): ...
@@ -11,7 +11,7 @@ PYI050.pyi:6:24: PYI050 Prefer `typing_extensions.Never` over `NoReturn` for arg
1111
8 | arg: typing_extensions.NoReturn,
1212
|
1313

14-
PYI050.pyi:10:44: PYI050 Prefer `typing_extensions.Never` over `NoReturn` for argument annotations
14+
PYI050.pyi:10:44: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations
1515
|
1616
8 | arg: typing_extensions.NoReturn,
1717
9 | ): ... # Error: PYI050
@@ -21,7 +21,7 @@ PYI050.pyi:10:44: PYI050 Prefer `typing_extensions.Never` over `NoReturn` for ar
2121
12 | def foo_never(arg: Never): ...
2222
|
2323

24-
PYI050.pyi:11:47: PYI050 Prefer `typing_extensions.Never` over `NoReturn` for argument annotations
24+
PYI050.pyi:11:47: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations
2525
|
2626
9 | ): ... # Error: PYI050
2727
10 | def foo_no_return_kwarg(arg: int, *, arg2: NoReturn): ... # Error: PYI050

crates/ruff/src/rules/flake8_use_pathlib/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ mod tests {
1212
use crate::assert_messages;
1313
use crate::registry::Rule;
1414
use crate::settings;
15-
use crate::settings::types::PythonVersion;
1615
use crate::test::test_path;
1716

1817
#[test_case(Path::new("full_name.py"))]
@@ -49,8 +48,7 @@ mod tests {
4948
Rule::OsPathSamefile,
5049
Rule::OsPathSplitext,
5150
Rule::BuiltinOpen,
52-
])
53-
.with_target_version(PythonVersion::latest()),
51+
]),
5452
)?;
5553
assert_messages!(snapshot, diagnostics);
5654
Ok(())
@@ -69,7 +67,7 @@ mod tests {
6967
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
7068
let diagnostics = test_path(
7169
Path::new("flake8_use_pathlib").join(path).as_path(),
72-
&settings::Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()),
70+
&settings::Settings::for_rule(rule_code),
7371
)?;
7472
assert_messages!(snapshot, diagnostics);
7573
Ok(())

crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__if_elif_else.py.snap

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ if_elif_else.py:6:1: I001 [*] Import block is un-sorted or un-formatted
1414
3 3 | elif "setuptools" in sys.modules:
1515
4 4 | from setuptools.command.sdist import sdist as _sdist
1616
5 5 | else:
17-
6 |- from setuptools.command.sdist import sdist as _sdist
18-
7 6 | from distutils.command.sdist import sdist as _sdist
19-
7 |+
20-
8 |+ from setuptools.command.sdist import sdist as _sdist
17+
6 |+ from distutils.command.sdist import sdist as _sdist
18+
6 7 | from setuptools.command.sdist import sdist as _sdist
19+
7 |- from distutils.command.sdist import sdist as _sdist
2120

2221

crates/ruff/src/rules/perflint/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod tests {
1010

1111
use crate::assert_messages;
1212
use crate::registry::Rule;
13+
use crate::settings::types::PythonVersion;
1314
use crate::settings::Settings;
1415
use crate::test::test_path;
1516

@@ -22,7 +23,7 @@ mod tests {
2223
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
2324
let diagnostics = test_path(
2425
Path::new("perflint").join(path).as_path(),
25-
&Settings::for_rule(rule_code),
26+
&Settings::for_rule(rule_code).with_target_version(PythonVersion::Py310),
2627
)?;
2728
assert_messages!(snapshot, diagnostics);
2829
Ok(())

crates/ruff/src/rules/pylint/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ mod tests {
130130
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
131131
let diagnostics = test_path(
132132
Path::new("pylint").join(path).as_path(),
133-
&Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()),
133+
&Settings::for_rule(rule_code),
134134
)?;
135135
assert_messages!(snapshot, diagnostics);
136136
Ok(())

crates/ruff/src/rules/pyupgrade/mod.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ mod tests {
7777
#[test_case(Rule::UselessObjectInheritance, Path::new("UP004.py"))]
7878
#[test_case(Rule::YieldInForLoop, Path::new("UP028_0.py"))]
7979
#[test_case(Rule::YieldInForLoop, Path::new("UP028_1.py"))]
80+
#[test_case(Rule::NonPEP695TypeAlias, Path::new("UP040.py"))]
8081
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
8182
let snapshot = path.to_string_lossy().to_string();
8283
let diagnostics = test_path(
8384
Path::new("pyupgrade").join(path).as_path(),
84-
&settings::Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()),
85+
&settings::Settings::for_rule(rule_code),
8586
)?;
8687
assert_messages!(snapshot, diagnostics);
8788
Ok(())
@@ -100,19 +101,6 @@ mod tests {
100101
Ok(())
101102
}
102103

103-
#[test]
104-
fn non_pep695_type_alias_py312() -> Result<()> {
105-
let diagnostics = test_path(
106-
Path::new("pyupgrade/UP040.py"),
107-
&settings::Settings {
108-
target_version: PythonVersion::Py312,
109-
..settings::Settings::for_rule(Rule::NonPEP695TypeAlias)
110-
},
111-
)?;
112-
assert_messages!(diagnostics);
113-
Ok(())
114-
}
115-
116104
#[test]
117105
fn future_annotations_keep_runtime_typing_p37() -> Result<()> {
118106
let diagnostics = test_path(

crates/ruff/src/rules/ruff/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ mod tests {
4444
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
4545
let diagnostics = test_path(
4646
Path::new("ruff").join(path).as_path(),
47-
&settings::Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()),
47+
&settings::Settings::for_rule(rule_code),
4848
)?;
4949
assert_messages!(snapshot, diagnostics);
5050
Ok(())

crates/ruff/src/settings/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,15 @@ impl Settings {
298298
pub fn for_rule(rule_code: Rule) -> Self {
299299
Self {
300300
rules: RuleTable::from_iter([rule_code]),
301+
target_version: PythonVersion::latest(),
301302
..Self::default()
302303
}
303304
}
304305

305306
pub fn for_rules(rules: impl IntoIterator<Item = Rule>) -> Self {
306307
Self {
307308
rules: RuleTable::from_iter(rules),
309+
target_version: PythonVersion::latest(),
308310
..Self::default()
309311
}
310312
}

crates/ruff/src/settings/types.rs

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl From<PythonVersion> for Pep440Version {
5353
}
5454

5555
impl PythonVersion {
56+
/// Return the latest supported Python version.
5657
pub const fn latest() -> Self {
5758
Self::Py312
5859
}

0 commit comments

Comments
 (0)