Skip to content

Commit 38b9fb8

Browse files
Set a default on PythonVersion (#6446)
## Summary I think it makes sense for `PythonVersion::default()` to return our minimum-supported non-EOL version. ## Test Plan `cargo test` --------- Co-authored-by: Zanie <[email protected]>
1 parent e4f5743 commit 38b9fb8

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

crates/ruff/src/settings/defaults.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ pub const PREFIXES: &[RuleSelector] = &[
2424
RuleSelector::Linter(Linter::Pyflakes),
2525
];
2626

27-
pub const TARGET_VERSION: PythonVersion = PythonVersion::Py38;
28-
2927
pub const TASK_TAGS: &[&str] = &["TODO", "FIXME", "XXX"];
3028

3129
pub static DUMMY_VARIABLE_RGX: Lazy<Regex> =
@@ -91,7 +89,7 @@ impl Default for Settings {
9189
respect_gitignore: true,
9290
src: vec![path_dedot::CWD.clone()],
9391
tab_size: TabSize::default(),
94-
target_version: TARGET_VERSION,
92+
target_version: PythonVersion::default(),
9593
task_tags: TASK_TAGS.iter().map(ToString::to_string).collect(),
9694
typing_modules: vec![],
9795
flake8_annotations: flake8_annotations::settings::Settings::default(),

crates/ruff/src/settings/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl Settings {
183183
.src
184184
.unwrap_or_else(|| vec![project_root.to_path_buf()]),
185185
project_root: project_root.to_path_buf(),
186-
target_version: config.target_version.unwrap_or(defaults::TARGET_VERSION),
186+
target_version: config.target_version.unwrap_or_default(),
187187
task_tags: config.task_tags.unwrap_or_else(|| {
188188
defaults::TASK_TAGS
189189
.iter()

crates/ruff/src/settings/types.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,25 @@ use crate::registry::RuleSet;
1919
use crate::rule_selector::RuleSelector;
2020

2121
#[derive(
22-
Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize, CacheKey, EnumIter,
22+
Clone,
23+
Copy,
24+
Debug,
25+
PartialOrd,
26+
Ord,
27+
PartialEq,
28+
Eq,
29+
Default,
30+
Serialize,
31+
Deserialize,
32+
CacheKey,
33+
EnumIter,
2334
)]
2435
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
2536
#[serde(rename_all = "lowercase")]
2637
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2738
pub enum PythonVersion {
2839
Py37,
40+
#[default]
2941
Py38,
3042
Py39,
3143
Py310,

crates/ruff_wasm/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use ruff::rules::{
2020
};
2121
use ruff::settings::configuration::Configuration;
2222
use ruff::settings::options::Options;
23+
use ruff::settings::types::PythonVersion;
2324
use ruff::settings::{defaults, flags, Settings};
2425
use ruff_python_ast::PySourceType;
2526
use ruff_python_codegen::Stylist;
@@ -134,7 +135,7 @@ impl Workspace {
134135
line_length: Some(LineLength::default()),
135136
select: Some(defaults::PREFIXES.to_vec()),
136137
tab_size: Some(TabSize::default()),
137-
target_version: Some(defaults::TARGET_VERSION),
138+
target_version: Some(PythonVersion::default()),
138139
// Ignore a bunch of options that don't make sense in a single-file editor.
139140
cache_dir: None,
140141
exclude: None,

0 commit comments

Comments
 (0)