Simplify formatting of strings by using flags from the AST nodes (#10489)

This commit is contained in:
Alex Waygood 2024-03-20 16:16:54 +00:00 committed by GitHub
parent fc792d1d2e
commit 7caf0d064a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 725 additions and 809 deletions

View file

@ -1,9 +1,9 @@
use crate::string_token_flags::StringKind;
use ruff_python_ast::AnyStringKind;
/// The context representing the current f-string that the lexer is in.
#[derive(Debug)]
pub(crate) struct FStringContext {
kind: StringKind,
kind: AnyStringKind,
/// The level of nesting for the lexer when it entered the current f-string.
/// The nesting level includes all kinds of parentheses i.e., round, square,
@ -17,7 +17,7 @@ pub(crate) struct FStringContext {
}
impl FStringContext {
pub(crate) const fn new(kind: StringKind, nesting: u32) -> Self {
pub(crate) const fn new(kind: AnyStringKind, nesting: u32) -> Self {
debug_assert!(kind.is_f_string());
Self {
kind,
@ -26,7 +26,7 @@ impl FStringContext {
}
}
pub(crate) const fn kind(&self) -> StringKind {
pub(crate) const fn kind(&self) -> AnyStringKind {
debug_assert!(self.kind.is_f_string());
self.kind
}