mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
Use ast::PythonVersion
internally in the formatter and linter (#16170)
## Summary This PR updates the formatter and linter to use the `PythonVersion` struct from the `ruff_python_ast` crate internally. While this doesn't remove the need for the `linter::PythonVersion` enum, it does remove the `formatter::PythonVersion` enum and limits the use in the linter to deserializing from CLI arguments and config files and moves most of the remaining methods to the `ast::PythonVersion` struct. ## Test Plan Existing tests, with some inputs and outputs updated to reflect the new (de)serialization format. I think these are test-specific and shouldn't affect any external (de)serialization. --------- Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
0868e73d2c
commit
a9efdea113
153 changed files with 456 additions and 539 deletions
|
@ -6,6 +6,7 @@ pub use generated::*;
|
|||
pub use int::*;
|
||||
pub use nodes::*;
|
||||
pub use operator_precedence::*;
|
||||
pub use python_version::*;
|
||||
|
||||
pub mod comparable;
|
||||
pub mod docstrings;
|
||||
|
@ -19,7 +20,7 @@ mod node;
|
|||
mod nodes;
|
||||
pub mod operator_precedence;
|
||||
pub mod parenthesize;
|
||||
pub mod python_version;
|
||||
mod python_version;
|
||||
pub mod relocate;
|
||||
pub mod script;
|
||||
pub mod statement_visitor;
|
||||
|
|
|
@ -4,6 +4,7 @@ use std::fmt;
|
|||
///
|
||||
/// N.B. This does not necessarily represent a Python version that we actually support.
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
#[cfg_attr(feature = "cache", derive(ruff_macros::CacheKey))]
|
||||
pub struct PythonVersion {
|
||||
pub major: u8,
|
||||
pub minor: u8,
|
||||
|
@ -43,9 +44,24 @@ impl PythonVersion {
|
|||
.into_iter()
|
||||
}
|
||||
|
||||
pub const fn latest() -> Self {
|
||||
Self::PY313
|
||||
}
|
||||
|
||||
pub const fn as_tuple(self) -> (u8, u8) {
|
||||
(self.major, self.minor)
|
||||
}
|
||||
|
||||
pub fn free_threaded_build_available(self) -> bool {
|
||||
self >= PythonVersion::PY313
|
||||
}
|
||||
|
||||
/// Return `true` if the current version supports [PEP 701].
|
||||
///
|
||||
/// [PEP 701]: https://peps.python.org/pep-0701/
|
||||
pub fn supports_pep_701(self) -> bool {
|
||||
self >= Self::PY312
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for PythonVersion {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue