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:
Brent Westbrook 2025-02-18 12:03:13 -05:00 committed by GitHub
parent 0868e73d2c
commit a9efdea113
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
153 changed files with 456 additions and 539 deletions

View file

@ -3848,9 +3848,7 @@ impl From<LintOptionsWire> for LintOptions {
mod tests {
use crate::options::Flake8SelfOptions;
use ruff_linter::rules::flake8_self;
use ruff_linter::settings::types::PythonVersion as LinterPythonVersion;
use ruff_python_ast::name::Name;
use ruff_python_formatter::PythonVersion as FormatterPythonVersion;
#[test]
fn flake8_self_options() {
@ -3898,28 +3896,4 @@ mod tests {
vec![Name::new_static("_foo"), Name::new_static("_bar")]
);
}
#[test]
fn formatter_and_linter_target_version_have_same_default() {
assert_eq!(
FormatterPythonVersion::default().as_tuple(),
LinterPythonVersion::default().as_tuple()
);
}
#[test]
fn formatter_and_linter_target_version_have_same_latest() {
assert_eq!(
FormatterPythonVersion::latest().as_tuple(),
LinterPythonVersion::latest().as_tuple()
);
}
#[test]
fn formatter_and_linter_target_version_have_same_minimal_supported() {
assert_eq!(
FormatterPythonVersion::minimal_supported().as_tuple(),
LinterPythonVersion::minimal_supported().as_tuple()
);
}
}