Add Python 3.14 to configuration options (#17647)

A small PR that just updates the various settings/configurations to
allow Python 3.14. At the moment selecting that target version will
have no impact compared to Python 3.13 - except that a warning
is emitted if the user does so with `preview` disabled.
This commit is contained in:
Dylan 2025-04-28 16:29:00 -05:00 committed by GitHub
parent 504fa20057
commit ae7691b026
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 32 additions and 5 deletions

View file

@ -30,14 +30,14 @@ use crate::fix::{fix_file, FixResult};
use crate::message::Message; use crate::message::Message;
use crate::noqa::add_noqa; use crate::noqa::add_noqa;
use crate::package::PackageRoot; use crate::package::PackageRoot;
use crate::preview::is_unsupported_syntax_enabled; use crate::preview::{is_py314_support_enabled, is_unsupported_syntax_enabled};
use crate::registry::{AsRule, Rule, RuleSet}; use crate::registry::{AsRule, Rule, RuleSet};
#[cfg(any(feature = "test-rules", test))] #[cfg(any(feature = "test-rules", test))]
use crate::rules::ruff::rules::test_rules::{self, TestRule, TEST_RULES}; use crate::rules::ruff::rules::test_rules::{self, TestRule, TEST_RULES};
use crate::settings::types::UnsafeFixes; use crate::settings::types::UnsafeFixes;
use crate::settings::{flags, LinterSettings}; use crate::settings::{flags, LinterSettings};
use crate::source_kind::SourceKind; use crate::source_kind::SourceKind;
use crate::{directives, fs, Locator}; use crate::{directives, fs, warn_user_once, Locator};
pub struct LinterResult { pub struct LinterResult {
/// A collection of diagnostic messages generated by the linter. /// A collection of diagnostic messages generated by the linter.
@ -450,6 +450,11 @@ pub fn lint_only(
source: ParseSource, source: ParseSource,
) -> LinterResult { ) -> LinterResult {
let target_version = settings.resolve_target_version(path); let target_version = settings.resolve_target_version(path);
if matches!(target_version, PythonVersion::PY314) && !is_py314_support_enabled(settings) {
warn_user_once!("Support for Python 3.14 is under development and may be unstable. Enable `preview` to remove this warning.");
}
let parsed = source.into_parsed(source_kind, source_type, target_version); let parsed = source.into_parsed(source_kind, source_type, target_version);
// Map row and column locations to byte slices (lazily). // Map row and column locations to byte slices (lazily).
@ -559,6 +564,10 @@ pub fn lint_fix<'a>(
let target_version = settings.resolve_target_version(path); let target_version = settings.resolve_target_version(path);
if matches!(target_version, PythonVersion::PY314) && !is_py314_support_enabled(settings) {
warn_user_once!("Support for Python 3.14 is under development and may be unstable. Enable `preview` to remove this warning.");
}
// Continuously fix until the source code stabilizes. // Continuously fix until the source code stabilizes.
loop { loop {
// Parse once. // Parse once.

View file

@ -18,6 +18,10 @@ pub(crate) const fn is_unsupported_syntax_enabled(settings: &LinterSettings) ->
settings.preview.is_enabled() settings.preview.is_enabled()
} }
pub(crate) const fn is_py314_support_enabled(settings: &LinterSettings) -> bool {
settings.preview.is_enabled()
}
// Rule-specific behavior // Rule-specific behavior
// https://github.com/astral-sh/ruff/pull/17136 // https://github.com/astral-sh/ruff/pull/17136

View file

@ -34,6 +34,7 @@ pub enum PythonVersion {
Py311, Py311,
Py312, Py312,
Py313, Py313,
Py314,
} }
impl Default for PythonVersion { impl Default for PythonVersion {
@ -55,6 +56,7 @@ impl TryFrom<ast::PythonVersion> for PythonVersion {
ast::PythonVersion::PY311 => Ok(Self::Py311), ast::PythonVersion::PY311 => Ok(Self::Py311),
ast::PythonVersion::PY312 => Ok(Self::Py312), ast::PythonVersion::PY312 => Ok(Self::Py312),
ast::PythonVersion::PY313 => Ok(Self::Py313), ast::PythonVersion::PY313 => Ok(Self::Py313),
ast::PythonVersion::PY314 => Ok(Self::Py314),
_ => Err(format!("unrecognized python version {value}")), _ => Err(format!("unrecognized python version {value}")),
} }
} }
@ -84,6 +86,7 @@ impl PythonVersion {
Self::Py311 => (3, 11), Self::Py311 => (3, 11),
Self::Py312 => (3, 12), Self::Py312 => (3, 12),
Self::Py313 => (3, 13), Self::Py313 => (3, 13),
Self::Py314 => (3, 14),
} }
} }
} }

View file

@ -30,6 +30,10 @@ impl PythonVersion {
major: 3, major: 3,
minor: 13, minor: 13,
}; };
pub const PY314: PythonVersion = PythonVersion {
major: 3,
minor: 14,
};
pub fn iter() -> impl Iterator<Item = PythonVersion> { pub fn iter() -> impl Iterator<Item = PythonVersion> {
[ [
@ -40,6 +44,7 @@ impl PythonVersion {
PythonVersion::PY311, PythonVersion::PY311,
PythonVersion::PY312, PythonVersion::PY312,
PythonVersion::PY313, PythonVersion::PY313,
PythonVersion::PY314,
] ]
.into_iter() .into_iter()
} }
@ -49,6 +54,7 @@ impl PythonVersion {
Self::PY37 Self::PY37
} }
// TODO: change this to 314 when it is released
pub const fn latest() -> Self { pub const fn latest() -> Self {
Self::PY313 Self::PY313
} }

View file

@ -608,7 +608,7 @@ Options:
RUFF_OUTPUT_FILE=] RUFF_OUTPUT_FILE=]
--target-version <TARGET_VERSION> --target-version <TARGET_VERSION>
The minimum Python version that should be supported [possible values: The minimum Python version that should be supported [possible values:
py37, py38, py39, py310, py311, py312, py313] py37, py38, py39, py310, py311, py312, py313, py314]
--preview --preview
Enable preview mode; checks will include unstable rules and fixes. Enable preview mode; checks will include unstable rules and fixes.
Use `--no-preview` to disable Use `--no-preview` to disable
@ -723,7 +723,7 @@ Options:
notebooks, use `--extension ipy:ipynb` notebooks, use `--extension ipy:ipynb`
--target-version <TARGET_VERSION> --target-version <TARGET_VERSION>
The minimum Python version that should be supported [possible values: The minimum Python version that should be supported [possible values:
py37, py38, py39, py310, py311, py312, py313] py37, py38, py39, py310, py311, py312, py313, py314]
--preview --preview
Enable preview mode; enables unstable formatting. Use `--no-preview` Enable preview mode; enables unstable formatting. Use `--no-preview`
to disable to disable

View file

@ -210,6 +210,10 @@
{ {
"description": "Python 3.13", "description": "Python 3.13",
"const": "3.13" "const": "3.13"
},
{
"description": "Python 3.14",
"const": "3.14"
} }
] ]
}, },

3
ruff.schema.json generated
View file

@ -2848,7 +2848,8 @@
"py310", "py310",
"py311", "py311",
"py312", "py312",
"py313" "py313",
"py314"
] ]
}, },
"Quote": { "Quote": {