Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions crates/ruff_linter/src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ use crate::fix::{fix_file, FixResult};
use crate::message::Message;
use crate::noqa::add_noqa;
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};
#[cfg(any(feature = "test-rules", test))]
use crate::rules::ruff::rules::test_rules::{self, TestRule, TEST_RULES};
use crate::settings::types::UnsafeFixes;
use crate::settings::{flags, LinterSettings};
use crate::source_kind::SourceKind;
use crate::{directives, fs, Locator};
use crate::{directives, fs, warn_user_once, Locator};

pub struct LinterResult {
/// A collection of diagnostic messages generated by the linter.
Expand Down Expand Up @@ -450,6 +450,11 @@ pub fn lint_only(
source: ParseSource,
) -> LinterResult {
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);

// Map row and column locations to byte slices (lazily).
Expand Down Expand Up @@ -559,6 +564,10 @@ pub fn lint_fix<'a>(

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.
loop {
// Parse once.
Expand Down
4 changes: 4 additions & 0 deletions crates/ruff_linter/src/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ pub(crate) const fn is_unsupported_syntax_enabled(settings: &LinterSettings) ->
settings.preview.is_enabled()
}

pub(crate) const fn is_py314_support_enabled(settings: &LinterSettings) -> bool {
settings.preview.is_enabled()
}

// Rule-specific behavior

// https://github.com/astral-sh/ruff/pull/17136
Expand Down
3 changes: 3 additions & 0 deletions crates/ruff_linter/src/settings/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub enum PythonVersion {
Py311,
Py312,
Py313,
Py314,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unfortunate that adding Py314 makes it appear in the JSON schema and clap documentation without the possibility of mentioning that Py314 support is in preview.

I think we should log a warning or even abort if a user specifies 3.14 and hasn't preview enabled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with a warning, feel free to bikeshed the message which is currently:

Support for Python 3.14 is under development and may be unstable. Enable preview to remove this warning.

}

impl Default for PythonVersion {
Expand All @@ -55,6 +56,7 @@ impl TryFrom<ast::PythonVersion> for PythonVersion {
ast::PythonVersion::PY311 => Ok(Self::Py311),
ast::PythonVersion::PY312 => Ok(Self::Py312),
ast::PythonVersion::PY313 => Ok(Self::Py313),
ast::PythonVersion::PY314 => Ok(Self::Py314),
_ => Err(format!("unrecognized python version {value}")),
}
}
Expand Down Expand Up @@ -84,6 +86,7 @@ impl PythonVersion {
Self::Py311 => (3, 11),
Self::Py312 => (3, 12),
Self::Py313 => (3, 13),
Self::Py314 => (3, 14),
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/ruff_python_ast/src/python_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ impl PythonVersion {
major: 3,
minor: 13,
};
pub const PY314: PythonVersion = PythonVersion {
major: 3,
minor: 14,
};

pub fn iter() -> impl Iterator<Item = PythonVersion> {
[
Expand All @@ -40,6 +44,7 @@ impl PythonVersion {
PythonVersion::PY311,
PythonVersion::PY312,
PythonVersion::PY313,
PythonVersion::PY314,
]
.into_iter()
}
Expand All @@ -49,6 +54,7 @@ impl PythonVersion {
Self::PY37
}

// TODO: change this to 314 when it is released
pub const fn latest() -> Self {
Self::PY313
}
Expand Down
4 changes: 2 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ Options:
RUFF_OUTPUT_FILE=]
--target-version <TARGET_VERSION>
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
Enable preview mode; checks will include unstable rules and fixes.
Use `--no-preview` to disable
Expand Down Expand Up @@ -723,7 +723,7 @@ Options:
notebooks, use `--extension ipy:ipynb`
--target-version <TARGET_VERSION>
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
Enable preview mode; enables unstable formatting. Use `--no-preview`
to disable
Expand Down
4 changes: 4 additions & 0 deletions knot.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@
{
"description": "Python 3.13",
"const": "3.13"
},
{
"description": "Python 3.14",
"const": "3.14"
}
]
},
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.

Loading