@@ -6,6 +6,7 @@ use ruff_formatter::printer::{LineEnding, PrinterOptions, SourceMapGeneration};
66use ruff_formatter:: { FormatOptions , IndentStyle , IndentWidth , LineWidth } ;
77use ruff_macros:: CacheKey ;
88use ruff_python_ast:: PySourceType ;
9+ use ruff_python_parser:: python_version:: PyVersion ;
910
1011/// Resolved options for formatting one individual file. The difference to `FormatterSettings`
1112/// is that `FormatterSettings` stores the settings for multiple files (the entire project, a subdirectory, ..)
@@ -21,7 +22,7 @@ pub struct PyFormatOptions {
2122
2223 /// The (minimum) Python version used to run the formatted code. This is used
2324 /// to determine the supported Python syntax.
24- target_version : PythonVersion ,
25+ target_version : PyVersion ,
2526
2627 /// Specifies the indent style:
2728 /// * Either a tab
@@ -80,7 +81,7 @@ impl Default for PyFormatOptions {
8081 fn default ( ) -> Self {
8182 Self {
8283 source_type : PySourceType :: default ( ) ,
83- target_version : PythonVersion :: default ( ) ,
84+ target_version : PyVersion :: default ( ) ,
8485 indent_style : default_indent_style ( ) ,
8586 line_width : default_line_width ( ) ,
8687 indent_width : default_indent_width ( ) ,
@@ -108,7 +109,7 @@ impl PyFormatOptions {
108109 }
109110 }
110111
111- pub const fn target_version ( & self ) -> PythonVersion {
112+ pub const fn target_version ( & self ) -> PyVersion {
112113 self . target_version
113114 }
114115
@@ -145,7 +146,7 @@ impl PyFormatOptions {
145146 }
146147
147148 #[ must_use]
148- pub fn with_target_version ( mut self , target_version : PythonVersion ) -> Self {
149+ pub fn with_target_version ( mut self , target_version : PyVersion ) -> Self {
149150 self . target_version = target_version;
150151 self
151152 }
@@ -468,52 +469,3 @@ where
468469 ) ) ,
469470 }
470471}
471-
472- #[ derive( CacheKey , Clone , Copy , Debug , PartialOrd , Ord , PartialEq , Eq , Default ) ]
473- #[ cfg_attr(
474- feature = "serde" ,
475- derive( serde:: Serialize , serde:: Deserialize ) ,
476- serde( rename_all = "lowercase" )
477- ) ]
478- #[ cfg_attr( feature = "schemars" , derive( schemars:: JsonSchema ) ) ]
479- pub enum PythonVersion {
480- Py37 ,
481- Py38 ,
482- // Make sure to also change the default for `ruff_linter::settings::types::PythonVersion`
483- // when changing the default here.
484- #[ default]
485- Py39 ,
486- Py310 ,
487- Py311 ,
488- Py312 ,
489- Py313 ,
490- }
491-
492- impl PythonVersion {
493- /// Return `true` if the current version supports [PEP 701].
494- ///
495- /// [PEP 701]: https://peps.python.org/pep-0701/
496- pub fn supports_pep_701 ( self ) -> bool {
497- self >= Self :: Py312
498- }
499-
500- pub fn as_tuple ( self ) -> ( u8 , u8 ) {
501- match self {
502- Self :: Py37 => ( 3 , 7 ) ,
503- Self :: Py38 => ( 3 , 8 ) ,
504- Self :: Py39 => ( 3 , 9 ) ,
505- Self :: Py310 => ( 3 , 10 ) ,
506- Self :: Py311 => ( 3 , 11 ) ,
507- Self :: Py312 => ( 3 , 12 ) ,
508- Self :: Py313 => ( 3 , 13 ) ,
509- }
510- }
511-
512- pub fn latest ( ) -> Self {
513- Self :: Py313
514- }
515-
516- pub fn minimal_supported ( ) -> Self {
517- Self :: Py37
518- }
519- }
0 commit comments