Skip to content

Commit d9b1167

Browse files
committed
warn when py314 selected and not in preview
1 parent c8aad5d commit d9b1167

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

crates/ruff_linter/src/linter.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ use crate::fix::{fix_file, FixResult};
3030
use crate::message::Message;
3131
use crate::noqa::add_noqa;
3232
use crate::package::PackageRoot;
33-
use crate::preview::is_unsupported_syntax_enabled;
33+
use crate::preview::{is_py314_support_enabled, is_unsupported_syntax_enabled};
3434
use crate::registry::{AsRule, Rule, RuleSet};
3535
#[cfg(any(feature = "test-rules", test))]
3636
use crate::rules::ruff::rules::test_rules::{self, TestRule, TEST_RULES};
3737
use crate::settings::types::UnsafeFixes;
3838
use crate::settings::{flags, LinterSettings};
3939
use crate::source_kind::SourceKind;
40-
use crate::{directives, fs, Locator};
40+
use crate::{directives, fs, warn_user_once, Locator};
4141

4242
pub struct LinterResult {
4343
/// A collection of diagnostic messages generated by the linter.
@@ -450,6 +450,11 @@ pub fn lint_only(
450450
source: ParseSource,
451451
) -> LinterResult {
452452
let target_version = settings.resolve_target_version(path);
453+
454+
if matches!(target_version, PythonVersion::PY314) && !is_py314_support_enabled(settings) {
455+
warn_user_once!("Support for Python 3.14 is under development and may be unstable. Enable `preview` to remove this warning.");
456+
}
457+
453458
let parsed = source.into_parsed(source_kind, source_type, target_version);
454459

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

560565
let target_version = settings.resolve_target_version(path);
561566

567+
if matches!(target_version, PythonVersion::PY314) && !is_py314_support_enabled(settings) {
568+
warn_user_once!("Support for Python 3.14 is under development and may be unstable. Enable `preview` to remove this warning.");
569+
}
570+
562571
// Continuously fix until the source code stabilizes.
563572
loop {
564573
// Parse once.

crates/ruff_linter/src/preview.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ pub(crate) const fn is_unsupported_syntax_enabled(settings: &LinterSettings) ->
1818
settings.preview.is_enabled()
1919
}
2020

21+
pub(crate) const fn is_py314_support_enabled(settings: &LinterSettings) -> bool {
22+
settings.preview.is_enabled()
23+
}
24+
2125
// Rule-specific behavior
2226

2327
// https://github.com/astral-sh/ruff/pull/17136

0 commit comments

Comments
 (0)