Skip to content

Commit eaada03

Browse files
authored
Set default version to py38 (#6444)
## Summary In #6397, the documentation was updated stating that the default target-version is now "py38", but the actual default value wasn't updated and remained py310. This commit updates the default value to match what the documentation says.
1 parent a39dd76 commit eaada03

File tree

11 files changed

+59
-26
lines changed

11 files changed

+59
-26
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod tests {
1111

1212
use crate::assert_messages;
1313
use crate::registry::Rule;
14+
use crate::settings::types::PythonVersion;
1415
use crate::settings::Settings;
1516
use crate::test::test_path;
1617

@@ -49,7 +50,6 @@ mod tests {
4950
#[test_case(Rule::UselessComparison, Path::new("B015.py"))]
5051
#[test_case(Rule::UselessContextlibSuppress, Path::new("B022.py"))]
5152
#[test_case(Rule::UselessExpression, Path::new("B018.py"))]
52-
#[test_case(Rule::ZipWithoutExplicitStrict, Path::new("B905.py"))]
5353
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
5454
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
5555
let diagnostics = test_path(
@@ -60,6 +60,18 @@ mod tests {
6060
Ok(())
6161
}
6262

63+
#[test]
64+
fn zip_without_explicit_strict() -> Result<()> {
65+
let snapshot = "B905.py";
66+
let diagnostics = test_path(
67+
Path::new("flake8_bugbear").join(snapshot).as_path(),
68+
&Settings::for_rule(Rule::ZipWithoutExplicitStrict)
69+
.with_target_version(PythonVersion::latest()),
70+
)?;
71+
assert_messages!(snapshot, diagnostics);
72+
Ok(())
73+
}
74+
6375
#[test]
6476
fn extend_immutable_calls() -> Result<()> {
6577
let snapshot = "extend_immutable_calls".to_string();

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ mod tests {
1212
use crate::assert_messages;
1313
use crate::registry::Rule;
1414
use crate::settings;
15+
use crate::settings::types::PythonVersion;
1516
use crate::test::test_path;
1617

1718
#[test_case(Path::new("full_name.py"))]
@@ -48,7 +49,8 @@ mod tests {
4849
Rule::OsPathSamefile,
4950
Rule::OsPathSplitext,
5051
Rule::BuiltinOpen,
51-
]),
52+
])
53+
.with_target_version(PythonVersion::latest()),
5254
)?;
5355
assert_messages!(snapshot, diagnostics);
5456
Ok(())
@@ -67,7 +69,7 @@ mod tests {
6769
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
6870
let diagnostics = test_path(
6971
Path::new("flake8_use_pathlib").join(path).as_path(),
70-
&settings::Settings::for_rule(rule_code),
72+
&settings::Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()),
7173
)?;
7274
assert_messages!(snapshot, diagnostics);
7375
Ok(())

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

Lines changed: 10 additions & 15 deletions
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_rules(vec![rule_code]),
133+
&Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()),
134134
)?;
135135
assert_messages!(snapshot, diagnostics);
136136
Ok(())
@@ -140,10 +140,8 @@ mod tests {
140140
fn repeated_isinstance_calls() -> Result<()> {
141141
let diagnostics = test_path(
142142
Path::new("pylint/repeated_isinstance_calls.py"),
143-
&Settings {
144-
target_version: PythonVersion::Py39,
145-
..Settings::for_rules(vec![Rule::RepeatedIsinstanceCalls])
146-
},
143+
&Settings::for_rule(Rule::RepeatedIsinstanceCalls)
144+
.with_target_version(PythonVersion::Py39),
147145
)?;
148146
assert_messages!(diagnostics);
149147
Ok(())
@@ -153,10 +151,7 @@ mod tests {
153151
fn continue_in_finally() -> Result<()> {
154152
let diagnostics = test_path(
155153
Path::new("pylint/continue_in_finally.py"),
156-
&Settings {
157-
target_version: PythonVersion::Py37,
158-
..Settings::for_rules(vec![Rule::ContinueInFinally])
159-
},
154+
&Settings::for_rule(Rule::ContinueInFinally).with_target_version(PythonVersion::Py37),
160155
)?;
161156
assert_messages!(diagnostics);
162157
Ok(())
@@ -171,7 +166,7 @@ mod tests {
171166
allow_magic_value_types: vec![pylint::settings::ConstantType::Int],
172167
..pylint::settings::Settings::default()
173168
},
174-
..Settings::for_rules(vec![Rule::MagicValueComparison])
169+
..Settings::for_rule(Rule::MagicValueComparison)
175170
},
176171
)?;
177172
assert_messages!(diagnostics);
@@ -187,7 +182,7 @@ mod tests {
187182
max_args: 4,
188183
..pylint::settings::Settings::default()
189184
},
190-
..Settings::for_rules(vec![Rule::TooManyArguments])
185+
..Settings::for_rule(Rule::TooManyArguments)
191186
},
192187
)?;
193188
assert_messages!(diagnostics);
@@ -200,7 +195,7 @@ mod tests {
200195
Path::new("pylint/too_many_arguments_params.py"),
201196
&Settings {
202197
dummy_variable_rgx: Regex::new(r"skip_.*").unwrap(),
203-
..Settings::for_rules(vec![Rule::TooManyArguments])
198+
..Settings::for_rule(Rule::TooManyArguments)
204199
},
205200
)?;
206201
assert_messages!(diagnostics);
@@ -216,7 +211,7 @@ mod tests {
216211
max_branches: 1,
217212
..pylint::settings::Settings::default()
218213
},
219-
..Settings::for_rules(vec![Rule::TooManyBranches])
214+
..Settings::for_rule(Rule::TooManyBranches)
220215
},
221216
)?;
222217
assert_messages!(diagnostics);
@@ -232,7 +227,7 @@ mod tests {
232227
max_statements: 1,
233228
..pylint::settings::Settings::default()
234229
},
235-
..Settings::for_rules(vec![Rule::TooManyStatements])
230+
..Settings::for_rule(Rule::TooManyStatements)
236231
},
237232
)?;
238233
assert_messages!(diagnostics);
@@ -248,7 +243,7 @@ mod tests {
248243
max_returns: 1,
249244
..pylint::settings::Settings::default()
250245
},
251-
..Settings::for_rules(vec![Rule::TooManyReturnStatements])
246+
..Settings::for_rule(Rule::TooManyReturnStatements)
252247
},
253248
)?;
254249
assert_messages!(diagnostics);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ mod tests {
8181
let snapshot = path.to_string_lossy().to_string();
8282
let diagnostics = test_path(
8383
Path::new("pyupgrade").join(path).as_path(),
84-
&settings::Settings::for_rule(rule_code),
84+
&settings::Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()),
8585
)?;
8686
assert_messages!(snapshot, diagnostics);
8787
Ok(())

crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP035.py.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,4 +974,19 @@ UP035.py:76:1: UP035 [*] Import from `collections.abc` instead: `Generator`
974974
78 78 | # OK
975975
79 79 | from a import b
976976

977+
UP035.py:88:1: UP035 [*] Import from `typing` instead: `dataclass_transform`
978+
|
979+
87 | # Ok: `typing_extensions` supports `frozen_default` (backported from 3.12).
980+
88 | from typing_extensions import dataclass_transform
981+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035
982+
|
983+
= help: Import from `typing`
984+
985+
Suggested fix
986+
85 85 | from typing_extensions import NamedTuple
987+
86 86 |
988+
87 87 | # Ok: `typing_extensions` supports `frozen_default` (backported from 3.12).
989+
88 |-from typing_extensions import dataclass_transform
990+
88 |+from typing import dataclass_transform
991+
977992

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

Lines changed: 3 additions & 5 deletions
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),
47+
&settings::Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()),
4848
)?;
4949
assert_messages!(snapshot, diagnostics);
5050
Ok(())
@@ -60,10 +60,8 @@ mod tests {
6060
);
6161
let diagnostics = test_path(
6262
Path::new("ruff").join(path).as_path(),
63-
&settings::Settings {
64-
target_version: PythonVersion::Py39,
65-
..settings::Settings::for_rule(Rule::ImplicitOptional)
66-
},
63+
&settings::Settings::for_rule(Rule::ImplicitOptional)
64+
.with_target_version(PythonVersion::Py39),
6765
)?;
6866
assert_messages!(snapshot, diagnostics);
6967
Ok(())

crates/ruff/src/settings/defaults.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub const PREFIXES: &[RuleSelector] = &[
2424
RuleSelector::Linter(Linter::Pyflakes),
2525
];
2626

27-
pub const TARGET_VERSION: PythonVersion = PythonVersion::Py310;
27+
pub const TARGET_VERSION: PythonVersion = PythonVersion::Py38;
2828

2929
pub const TASK_TAGS: &[&str] = &["TODO", "FIXME", "XXX"];
3030

crates/ruff/src/settings/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,13 @@ impl Settings {
308308
..Self::default()
309309
}
310310
}
311+
312+
/// Return the [`Settings`] after updating the target [`PythonVersion`].
313+
#[must_use]
314+
pub fn with_target_version(mut self, target_version: PythonVersion) -> Self {
315+
self.target_version = target_version;
316+
self
317+
}
311318
}
312319

313320
impl From<&Configuration> for RuleTable {

crates/ruff/src/settings/options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ pub struct Options {
456456
/// contained an `__init__.py` file.
457457
pub namespace_packages: Option<Vec<String>>,
458458
#[option(
459-
default = r#""py310""#,
459+
default = r#""py38""#,
460460
value_type = r#""py37" | "py38" | "py39" | "py310" | "py311" | "py312""#,
461461
example = r#"
462462
# Always generate Python 3.7-compatible code.

crates/ruff/src/settings/types.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ impl From<PythonVersion> for Pep440Version {
4141
}
4242

4343
impl PythonVersion {
44+
pub const fn latest() -> Self {
45+
Self::Py312
46+
}
47+
4448
pub const fn as_tuple(&self) -> (u32, u32) {
4549
match self {
4650
Self::Py37 => (3, 7),

0 commit comments

Comments
 (0)