diff --git a/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs b/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs index c2813769b6..f178e3e8cb 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs @@ -281,8 +281,15 @@ const TYPING_EXTENSIONS_TO_TYPING_311: &[&str] = &[ "get_overloads", "overload", "reveal_type", - // Introduced in Python 3.11, but `typing_extensions` backports the `frozen_default` argument. - // "dataclass_transform", +]; + +// Python 3.12+ + +// Members of `typing_extensions` that were moved to `typing`. +const TYPING_EXTENSIONS_TO_TYPING_312: &[&str] = &[ + // Introduced in Python 3.11, but `typing_extensions` backports the `frozen_default` argument, + // which was introduced in Python 3.12. + "dataclass_transform", ]; struct ImportReplacer<'a> { @@ -369,6 +376,9 @@ impl<'a> ImportReplacer<'a> { if self.version >= PythonVersion::Py311 { typing_extensions_to_typing.extend(TYPING_EXTENSIONS_TO_TYPING_311); } + if self.version >= PythonVersion::Py312 { + typing_extensions_to_typing.extend(TYPING_EXTENSIONS_TO_TYPING_312); + } if let Some(operation) = self.try_replace(&typing_extensions_to_typing, "typing") { operations.push(operation); } diff --git a/crates/ruff/src/settings/options.rs b/crates/ruff/src/settings/options.rs index ea18f0cb6d..ef5a6a3597 100644 --- a/crates/ruff/src/settings/options.rs +++ b/crates/ruff/src/settings/options.rs @@ -433,7 +433,7 @@ pub struct Options { pub namespace_packages: Option>, #[option( default = r#""py310""#, - value_type = r#""py37" | "py38" | "py39" | "py310" | "py311""#, + value_type = r#""py37" | "py38" | "py39" | "py310" | "py311" | "py312""#, example = r#" # Always generate Python 3.7-compatible code. target-version = "py37" diff --git a/crates/ruff/src/settings/types.rs b/crates/ruff/src/settings/types.rs index 63e6376e93..ca813bcb0a 100644 --- a/crates/ruff/src/settings/types.rs +++ b/crates/ruff/src/settings/types.rs @@ -30,6 +30,7 @@ pub enum PythonVersion { Py39, Py310, Py311, + Py312, } impl From for Pep440Version { @@ -47,6 +48,7 @@ impl PythonVersion { Self::Py39 => (3, 9), Self::Py310 => (3, 10), Self::Py311 => (3, 11), + Self::Py312 => (3, 12), } } diff --git a/docs/configuration.md b/docs/configuration.md index 538e19ce8f..20ee6ba11a 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -215,7 +215,7 @@ Options: -o, --output-file Specify file to write the linter output to (default: stdout) --target-version - The minimum Python version that should be supported [possible values: py37, py38, py39, py310, py311] + The minimum Python version that should be supported [possible values: py37, py38, py39, py310, py311, py312] --config Path to the `pyproject.toml` or `ruff.toml` file to use for configuration --statistics diff --git a/ruff.schema.json b/ruff.schema.json index b6c0437890..a30f989acf 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -1555,7 +1555,8 @@ "py38", "py39", "py310", - "py311" + "py311", + "py312" ] }, "Quote": {