Skip to content

Commit

Permalink
Add PythonVersion::Py312
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jun 22, 2023
1 parent 5f88ff8 commit 1aecc73
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
14 changes: 12 additions & 2 deletions crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/settings/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ pub struct Options {
pub namespace_packages: Option<Vec<String>>,
#[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"
Expand Down
2 changes: 2 additions & 0 deletions crates/ruff/src/settings/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub enum PythonVersion {
Py39,
Py310,
Py311,
Py312,
}

impl From<PythonVersion> for Pep440Version {
Expand All @@ -47,6 +48,7 @@ impl PythonVersion {
Self::Py39 => (3, 9),
Self::Py310 => (3, 10),
Self::Py311 => (3, 11),
Self::Py312 => (3, 12),
}
}

Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Options:
-o, --output-file <OUTPUT_FILE>
Specify file to write the linter output to (default: stdout)
--target-version <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 <CONFIG>
Path to the `pyproject.toml` or `ruff.toml` file to use for configuration
--statistics
Expand Down
3 changes: 2 additions & 1 deletion ruff.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1aecc73

Please sign in to comment.