Skip to content

Commit fddc510

Browse files
committed
feat(ruff): add Python 3.15 support and retire RUF017
1 parent d035744 commit fddc510

File tree

7 files changed

+40
-5
lines changed

7 files changed

+40
-5
lines changed

crates/ruff_linter/src/linter.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ use crate::doc_lines::{doc_lines_from_ast, doc_lines_from_tokens};
2626
use crate::fix::{FixResult, fix_file};
2727
use crate::noqa::add_noqa;
2828
use crate::package::PackageRoot;
29+
use crate::preview::is_py315_support_enabled;
2930
use crate::registry::Rule;
3031
#[cfg(any(feature = "test-rules", test))]
3132
use crate::rules::ruff::rules::test_rules::{self, TEST_RULES, TestRule};
3233
use crate::settings::types::UnsafeFixes;
3334
use crate::settings::{LinterSettings, TargetVersion, flags};
3435
use crate::source_kind::SourceKind;
3536
use crate::suppression::Suppressions;
36-
use crate::{Locator, directives, fs};
37+
use crate::{Locator, directives, fs, warn_user_once};
3738

3839
pub(crate) mod float;
3940

@@ -450,6 +451,14 @@ pub fn lint_only(
450451
) -> LinterResult {
451452
let target_version = settings.resolve_target_version(path);
452453

454+
if matches!(target_version.linter_version(), PythonVersion::PY315)
455+
&& !is_py315_support_enabled(settings)
456+
{
457+
warn_user_once!(
458+
"Support for Python 3.15 is under development and may be unstable. Enable `preview` to remove this warning."
459+
);
460+
}
461+
453462
let parsed = source.into_parsed(source_kind, source_type, target_version.parser_version());
454463

455464
// Map row and column locations to byte slices (lazily).
@@ -555,6 +564,14 @@ pub fn lint_fix<'a>(
555564

556565
let target_version = settings.resolve_target_version(path);
557566

567+
if matches!(target_version.linter_version(), PythonVersion::PY315)
568+
&& !is_py315_support_enabled(settings)
569+
{
570+
warn_user_once!(
571+
"Support for Python 3.15 is under development and may be unstable. Enable `preview` to remove this warning."
572+
);
573+
}
574+
558575
// Continuously fix until the source code stabilizes.
559576
loop {
560577
// Parse once.

crates/ruff_linter/src/preview.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,8 @@ pub(crate) const fn is_s310_resolve_string_literal_bindings_enabled(
296296
pub(crate) const fn is_range_suppressions_enabled(settings: &LinterSettings) -> bool {
297297
settings.preview.is_enabled()
298298
}
299+
300+
// https://github.com/astral-sh/ruff/pull/22419
301+
pub(crate) const fn is_py315_support_enabled(settings: &LinterSettings) -> bool {
302+
settings.preview.is_enabled()
303+
}

crates/ruff_linter/src/settings/types.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub enum PythonVersion {
3636
Py312,
3737
Py313,
3838
Py314,
39+
Py315,
3940
}
4041

4142
impl Default for PythonVersion {
@@ -58,6 +59,7 @@ impl TryFrom<ast::PythonVersion> for PythonVersion {
5859
ast::PythonVersion::PY312 => Ok(Self::Py312),
5960
ast::PythonVersion::PY313 => Ok(Self::Py313),
6061
ast::PythonVersion::PY314 => Ok(Self::Py314),
62+
ast::PythonVersion::PY315 => Ok(Self::Py315),
6163
_ => Err(format!("unrecognized python version {value}")),
6264
}
6365
}
@@ -88,6 +90,7 @@ impl PythonVersion {
8890
Self::Py312 => (3, 12),
8991
Self::Py313 => (3, 13),
9092
Self::Py314 => (3, 14),
93+
Self::Py315 => (3, 15),
9194
}
9295
}
9396
}

crates/ruff_python_ast/src/python_version.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ impl PythonVersion {
3535
major: 3,
3636
minor: 14,
3737
};
38+
pub const PY315: PythonVersion = PythonVersion {
39+
major: 3,
40+
minor: 15,
41+
};
3842

3943
pub fn iter() -> impl Iterator<Item = PythonVersion> {
4044
[
@@ -46,6 +50,7 @@ impl PythonVersion {
4650
PythonVersion::PY312,
4751
PythonVersion::PY313,
4852
PythonVersion::PY314,
53+
PythonVersion::PY315,
4954
]
5055
.into_iter()
5156
}
@@ -61,7 +66,7 @@ impl PythonVersion {
6166

6267
/// The latest Python version supported in preview
6368
pub fn latest_preview() -> Self {
64-
let latest_preview = Self::PY314;
69+
let latest_preview = Self::PY315;
6570
debug_assert!(latest_preview >= Self::latest());
6671
latest_preview
6772
}

docs/configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ Options:
610610
RUFF_OUTPUT_FILE=]
611611
--target-version <TARGET_VERSION>
612612
The minimum Python version that should be supported [possible values:
613-
py37, py38, py39, py310, py311, py312, py313, py314]
613+
py37, py38, py39, py310, py311, py312, py313, py314, py315]
614614
--preview
615615
Enable preview mode; checks will include unstable rules and fixes.
616616
Use `--no-preview` to disable
@@ -726,7 +726,7 @@ Options:
726726
notebooks, use `--extension ipy:ipynb`
727727
--target-version <TARGET_VERSION>
728728
The minimum Python version that should be supported [possible values:
729-
py37, py38, py39, py310, py311, py312, py313, py314]
729+
py37, py38, py39, py310, py311, py312, py313, py314, py315]
730730
--preview
731731
Enable preview mode; enables unstable formatting. Use `--no-preview`
732732
to disable

ruff.schema.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ty.schema.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)