13
13
ruff_text_size:: { Ranged , TextLen , TextRange , TextSize } ,
14
14
} ;
15
15
16
- use crate :: { prelude:: * , FormatModuleError , QuoteStyle } ;
16
+ use crate :: { prelude:: * , FormatModuleError } ;
17
17
18
- use super :: NormalizedString ;
18
+ use super :: { NormalizedString , QuoteChar } ;
19
19
20
20
/// Format a docstring by trimming whitespace and adjusting the indentation.
21
21
///
@@ -139,7 +139,7 @@ pub(super) fn format(normalized: &NormalizedString, f: &mut PyFormatter) -> Form
139
139
140
140
// Edge case: The first line is `""" "content`, so we need to insert chaperone space that keep
141
141
// inner quotes and closing quotes from getting to close to avoid `""""content`
142
- if trim_both. starts_with ( normalized. quotes . style . as_char ( ) ) {
142
+ if trim_both. starts_with ( normalized. quotes . quote_char . as_char ( ) ) {
143
143
space ( ) . fmt ( f) ?;
144
144
}
145
145
@@ -192,7 +192,7 @@ pub(super) fn format(normalized: &NormalizedString, f: &mut PyFormatter) -> Form
192
192
offset,
193
193
stripped_indentation_length,
194
194
already_normalized,
195
- quote_style : normalized. quotes . style ,
195
+ quote_char : normalized. quotes . quote_char ,
196
196
code_example : CodeExample :: default ( ) ,
197
197
}
198
198
. add_iter ( lines) ?;
@@ -250,8 +250,8 @@ struct DocstringLinePrinter<'ast, 'buf, 'fmt, 'src> {
250
250
/// is, the formatter can take a fast path.
251
251
already_normalized : bool ,
252
252
253
- /// The quote style used by the docstring being printed.
254
- quote_style : QuoteStyle ,
253
+ /// The quote character used by the docstring being printed.
254
+ quote_char : QuoteChar ,
255
255
256
256
/// The current code example detected in the docstring.
257
257
code_example : CodeExample < ' src > ,
@@ -476,7 +476,7 @@ impl<'ast, 'buf, 'fmt, 'src> DocstringLinePrinter<'ast, 'buf, 'fmt, 'src> {
476
476
// instead of later, and as a result, get more consistent
477
477
// results.
478
478
. with_indent_style ( IndentStyle :: Space ) ;
479
- let printed = match docstring_format_source ( options, self . quote_style , & codeblob) {
479
+ let printed = match docstring_format_source ( options, self . quote_char , & codeblob) {
480
480
Ok ( printed) => printed,
481
481
Err ( FormatModuleError :: FormatError ( err) ) => return Err ( err) ,
482
482
Err (
@@ -498,9 +498,11 @@ impl<'ast, 'buf, 'fmt, 'src> DocstringLinePrinter<'ast, 'buf, 'fmt, 'src> {
498
498
// a docstring. As we fix corner cases over time, we can perhaps
499
499
// remove this check. See the `doctest_invalid_skipped` tests in
500
500
// `docstring_code_examples.py` for when this check is relevant.
501
- let wrapped = match self . quote_style {
502
- QuoteStyle :: Single => std:: format!( "'''{}'''" , printed. as_code( ) ) ,
503
- QuoteStyle :: Double => std:: format!( r#""""{}""""# , printed. as_code( ) ) ,
501
+ let wrapped = match self . quote_char {
502
+ QuoteChar :: Single => std:: format!( "'''{}'''" , printed. as_code( ) ) ,
503
+ QuoteChar :: Double => {
504
+ std:: format!( r#""""{}""""# , printed. as_code( ) )
505
+ }
504
506
} ;
505
507
let result = ruff_python_parser:: parse (
506
508
& wrapped,
@@ -1483,7 +1485,7 @@ enum CodeExampleAddAction<'src> {
1483
1485
/// inside of a docstring.
1484
1486
fn docstring_format_source (
1485
1487
options : crate :: PyFormatOptions ,
1486
- docstring_quote_style : QuoteStyle ,
1488
+ docstring_quote_style : QuoteChar ,
1487
1489
source : & str ,
1488
1490
) -> Result < Printed , FormatModuleError > {
1489
1491
use ruff_python_parser:: AsMode ;
@@ -1510,7 +1512,7 @@ fn docstring_format_source(
1510
1512
/// that avoids `content""""` and `content\"""`. This does only applies to un-escaped backslashes,
1511
1513
/// so `content\\ """` doesn't need a space while `content\\\ """` does.
1512
1514
fn needs_chaperone_space ( normalized : & NormalizedString , trim_end : & str ) -> bool {
1513
- trim_end. ends_with ( normalized. quotes . style . as_char ( ) )
1515
+ trim_end. ends_with ( normalized. quotes . quote_char . as_char ( ) )
1514
1516
|| trim_end. chars ( ) . rev ( ) . take_while ( |c| * c == '\\' ) . count ( ) % 2 == 1
1515
1517
}
1516
1518
0 commit comments