mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 05:15:12 +00:00
Rename AnyStringKind
-> AnyStringFlags
(#11405)
## Summary This PR renames `AnyStringKind` to `AnyStringFlags` and `AnyStringFlags` to `AnyStringFlagsInner`. The main motivation is to have consistent usage of "kind" and "flags". For each string kind, it's "flags" like `StringLiteralFlags`, `BytesLiteralFlags`, and `FStringFlags` but it was `AnyStringKind` for the "any" variant.
This commit is contained in:
parent
be0ccabbaa
commit
6ecb4776de
54 changed files with 378 additions and 371 deletions
|
@ -1,5 +1,5 @@
|
|||
use ruff_formatter::write;
|
||||
use ruff_python_ast::{AnyStringKind, FString};
|
||||
use ruff_python_ast::{AnyStringFlags, FString};
|
||||
use ruff_source_file::Locator;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
@ -56,7 +56,9 @@ impl Format<PyFormatContext<'_>> for FormatFString<'_> {
|
|||
return result;
|
||||
}
|
||||
|
||||
let string_kind = normalizer.choose_quotes(self.value.into(), &locator).kind();
|
||||
let string_kind = normalizer
|
||||
.choose_quotes(self.value.into(), &locator)
|
||||
.flags();
|
||||
|
||||
let context = FStringContext::new(
|
||||
string_kind,
|
||||
|
@ -83,17 +85,17 @@ impl Format<PyFormatContext<'_>> for FormatFString<'_> {
|
|||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(crate) struct FStringContext {
|
||||
kind: AnyStringKind,
|
||||
flags: AnyStringFlags,
|
||||
layout: FStringLayout,
|
||||
}
|
||||
|
||||
impl FStringContext {
|
||||
const fn new(kind: AnyStringKind, layout: FStringLayout) -> Self {
|
||||
Self { kind, layout }
|
||||
const fn new(flags: AnyStringFlags, layout: FStringLayout) -> Self {
|
||||
Self { flags, layout }
|
||||
}
|
||||
|
||||
pub(crate) fn kind(self) -> AnyStringKind {
|
||||
self.kind
|
||||
pub(crate) fn flags(self) -> AnyStringFlags {
|
||||
self.flags
|
||||
}
|
||||
|
||||
pub(crate) const fn layout(self) -> FStringLayout {
|
||||
|
|
|
@ -56,7 +56,7 @@ impl<'a> FormatFStringLiteralElement<'a> {
|
|||
impl Format<PyFormatContext<'_>> for FormatFStringLiteralElement<'_> {
|
||||
fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
let literal_content = f.context().locator().slice(self.element.range());
|
||||
let normalized = normalize_string(literal_content, 0, self.context.kind(), true);
|
||||
let normalized = normalize_string(literal_content, 0, self.context.flags(), true);
|
||||
match &normalized {
|
||||
Cow::Borrowed(_) => source_text_slice(self.element.range()).fmt(f),
|
||||
Cow::Owned(normalized) => text(normalized).fmt(f),
|
||||
|
@ -102,7 +102,7 @@ impl FStringExpressionElementContext {
|
|||
// But, if the original source code already contained a newline, they'll be preserved.
|
||||
//
|
||||
// The Python version is irrelevant in this case.
|
||||
&& !(self.parent_context.kind().is_triple_quoted() && self.has_format_spec)
|
||||
&& !(self.parent_context.flags().is_triple_quoted() && self.has_format_spec)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue