diff --git a/crates/red_knot/src/target_version.rs b/crates/red_knot/src/target_version.rs index 7db3c514e8..e7c7b919b6 100644 --- a/crates/red_knot/src/target_version.rs +++ b/crates/red_knot/src/target_version.rs @@ -4,8 +4,8 @@ #[derive(Copy, Clone, Hash, Debug, PartialEq, Eq, PartialOrd, Ord, Default, clap::ValueEnum)] pub enum TargetVersion { Py37, - #[default] Py38, + #[default] Py39, Py310, Py311, @@ -46,3 +46,17 @@ impl From for red_knot_python_semantic::PythonVersion { } } } + +#[cfg(test)] +mod tests { + use crate::target_version::TargetVersion; + use red_knot_python_semantic::PythonVersion; + + #[test] + fn same_default_as_python_version() { + assert_eq!( + PythonVersion::from(TargetVersion::default()), + PythonVersion::default() + ); + } +} diff --git a/crates/red_knot_wasm/src/lib.rs b/crates/red_knot_wasm/src/lib.rs index 63b67240ad..d9f7514509 100644 --- a/crates/red_knot_wasm/src/lib.rs +++ b/crates/red_knot_wasm/src/lib.rs @@ -184,8 +184,8 @@ impl Settings { #[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Default)] pub enum TargetVersion { Py37, - #[default] Py38, + #[default] Py39, Py310, Py311, @@ -291,3 +291,17 @@ impl System for WasmSystem { fn not_found() -> std::io::Error { std::io::Error::new(std::io::ErrorKind::NotFound, "No such file or directory") } + +#[cfg(test)] +mod tests { + use crate::TargetVersion; + use red_knot_python_semantic::PythonVersion; + + #[test] + fn same_default_as_python_version() { + assert_eq!( + PythonVersion::from(TargetVersion::default()), + PythonVersion::default() + ); + } +} diff --git a/crates/ruff_linter/src/settings/types.rs b/crates/ruff_linter/src/settings/types.rs index e0f38391f5..5655a4baec 100644 --- a/crates/ruff_linter/src/settings/types.rs +++ b/crates/ruff_linter/src/settings/types.rs @@ -68,6 +68,10 @@ impl PythonVersion { Self::Py313 } + pub const fn minimal_supported() -> Self { + Self::Py37 + } + pub const fn as_tuple(&self) -> (u8, u8) { match self { Self::Py37 => (3, 7), diff --git a/crates/ruff_python_formatter/src/options.rs b/crates/ruff_python_formatter/src/options.rs index 541bac549f..e51aed0368 100644 --- a/crates/ruff_python_formatter/src/options.rs +++ b/crates/ruff_python_formatter/src/options.rs @@ -475,4 +475,24 @@ impl PythonVersion { pub fn supports_pep_701(self) -> bool { self >= Self::Py312 } + + pub fn as_tuple(self) -> (u8, u8) { + match self { + Self::Py37 => (3, 7), + Self::Py38 => (3, 8), + Self::Py39 => (3, 9), + Self::Py310 => (3, 10), + Self::Py311 => (3, 11), + Self::Py312 => (3, 12), + Self::Py313 => (3, 13), + } + } + + pub fn latest() -> Self { + Self::Py313 + } + + pub fn minimal_supported() -> Self { + Self::Py37 + } } diff --git a/crates/ruff_workspace/src/options.rs b/crates/ruff_workspace/src/options.rs index 1bc15d0d6a..f010c3c173 100644 --- a/crates/ruff_workspace/src/options.rs +++ b/crates/ruff_workspace/src/options.rs @@ -3408,7 +3408,9 @@ pub struct AnalyzeOptions { mod tests { use crate::options::Flake8SelfOptions; use ruff_linter::rules::flake8_self; + use ruff_linter::settings::types::PythonVersion as LinterPythonVersion; use ruff_python_ast::name::Name; + use ruff_python_formatter::PythonVersion as FormatterPythonVersion; #[test] fn flake8_self_options() { @@ -3456,4 +3458,28 @@ mod tests { vec![Name::new_static("_foo"), Name::new_static("_bar")] ); } + + #[test] + fn formatter_and_linter_target_version_have_same_default() { + assert_eq!( + FormatterPythonVersion::default().as_tuple(), + LinterPythonVersion::default().as_tuple() + ); + } + + #[test] + fn formatter_and_linter_target_version_have_same_latest() { + assert_eq!( + FormatterPythonVersion::latest().as_tuple(), + LinterPythonVersion::latest().as_tuple() + ); + } + + #[test] + fn formatter_and_linter_target_version_have_same_minimal_supported() { + assert_eq!( + FormatterPythonVersion::minimal_supported().as_tuple(), + LinterPythonVersion::minimal_supported().as_tuple() + ); + } }