Skip to content

Commit

Permalink
FStringPart: String(StringTodoName) -> Literal(PartialString)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidszotten committed Aug 20, 2023
1 parent 45ff90c commit 0f3ac34
Show file tree
Hide file tree
Showing 30 changed files with 103 additions and 103 deletions.
2 changes: 1 addition & 1 deletion crates/ruff/src/rules/flake8_pytest_style/rules/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub(super) fn is_empty_or_null_string(expr: &Expr) -> bool {

fn is_empty_or_null_string_part(part: &ast::FStringPart) -> bool {
match part {
ast::FStringPart::String(ast::StringTodoName { value, .. }) => value.is_empty(),
ast::FStringPart::Literal(ast::PartialString { value, .. }) => value.is_empty(),
ast::FStringPart::FormattedValue(ast::FormattedValue { expression, .. }) => {
is_empty_or_null_string(expression)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/rules/flynt/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn to_formatted_value_expr(inner: &Expr) -> ast::FStringPart {

/// Convert a string to a constant string expression.
pub(super) fn to_constant_string(s: &str) -> ast::FStringPart {
ast::FStringPart::String(ast::StringTodoName {
ast::FStringPart::Literal(ast::PartialString {
value: s.to_owned(),
range: TextRange::default(),
})
Expand Down Expand Up @@ -56,7 +56,7 @@ pub(super) fn to_fstring_part(expr: &Expr) -> Option<ast::FStringPart> {
value: Constant::Str(value),
range,
..
}) => Some(ast::FStringPart::String(ast::StringTodoName {
}) => Some(ast::FStringPart::Literal(ast::PartialString {
value: value.to_string(),
range: *range,
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ pub(crate) fn assert_on_string_literal(checker: &mut Checker, test: &Expr) {
checker.diagnostics.push(Diagnostic::new(
AssertOnStringLiteral {
kind: if parts.iter().all(|part| match part {
ast::FStringPart::String(ast::StringTodoName { value, .. }) => {
ast::FStringPart::Literal(ast::PartialString { value, .. }) => {
value.is_empty()
}
ast::FStringPart::FormattedValue(_) => false,
}) {
Kind::Empty
} else if parts.iter().any(|part| match part {
ast::FStringPart::String(ast::StringTodoName { value, .. }) => {
ast::FStringPart::Literal(ast::PartialString { value, .. }) => {
!value.is_empty()
}
ast::FStringPart::FormattedValue(_) => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn contains_message(expr: &Expr) -> bool {
match expr {
Expr::FString(ast::ExprFString { parts, .. }) => {
for part in parts {
if let ast::FStringPart::String(ast::StringTodoName { value, .. }) = part {
if let ast::FStringPart::Literal(ast::PartialString { value, .. }) = part {
if value.chars().any(char::is_whitespace) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_python_ast/src/comparable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ impl<'a> From<&'a ast::ExceptHandler> for ComparableExceptHandler<'a> {

#[derive(Debug, PartialEq, Eq, Hash)]
pub enum ComparableFStringPart<'a> {
String(&'a str),
Literal(&'a str),
FormattedValue(FormattedValue<'a>),
}

Expand All @@ -512,7 +512,7 @@ pub struct FormattedValue<'a> {
impl<'a> From<&'a ast::FStringPart> for ComparableFStringPart<'a> {
fn from(fstring_part: &'a ast::FStringPart) -> Self {
match fstring_part {
ast::FStringPart::String(ast::StringTodoName { value, .. }) => Self::String(value),
ast::FStringPart::Literal(ast::PartialString { value, .. }) => Self::Literal(value),
ast::FStringPart::FormattedValue(formatted_value) => {
Self::FormattedValue(FormattedValue {
expression: (&formatted_value.expression).into(),
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_python_ast/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ where
F: Fn(&Expr) -> bool,
{
match part {
FStringPart::String(_) => false,
FStringPart::Literal(_) => false,
FStringPart::FormattedValue(ast::FormattedValue {
expression,
format_spec,
Expand Down Expand Up @@ -1102,7 +1102,7 @@ impl Truthiness {
if parts.is_empty() {
Some(false)
} else if parts.iter().any(|part| match part {
ast::FStringPart::String(ast::StringTodoName { value, .. }) => {
ast::FStringPart::Literal(ast::PartialString { value, .. }) => {
!value.is_empty()
}
ast::FStringPart::FormattedValue(_) => true,
Expand Down
56 changes: 28 additions & 28 deletions crates/ruff_python_ast/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub enum AnyNode {
ExprIpyEscapeCommand(ast::ExprIpyEscapeCommand),
ExceptHandlerExceptHandler(ast::ExceptHandlerExceptHandler),
FormattedValue(ast::FormattedValue),
StringTodoName(ast::StringTodoName),
PartialString(ast::PartialString),
PatternMatchValue(ast::PatternMatchValue),
PatternMatchSingleton(ast::PatternMatchSingleton),
PatternMatchSequence(ast::PatternMatchSequence),
Expand Down Expand Up @@ -157,7 +157,7 @@ impl AnyNode {
| AnyNode::ExprCompare(_)
| AnyNode::ExprCall(_)
| AnyNode::FormattedValue(_)
| AnyNode::StringTodoName(_)
| AnyNode::PartialString(_)
| AnyNode::ExprFString(_)
| AnyNode::ExprConstant(_)
| AnyNode::ExprAttribute(_)
Expand Down Expand Up @@ -254,7 +254,7 @@ impl AnyNode {
| AnyNode::StmtIpyEscapeCommand(_)
| AnyNode::ExceptHandlerExceptHandler(_)
| AnyNode::FormattedValue(_)
| AnyNode::StringTodoName(_)
| AnyNode::PartialString(_)
| AnyNode::PatternMatchValue(_)
| AnyNode::PatternMatchSingleton(_)
| AnyNode::PatternMatchSequence(_)
Expand Down Expand Up @@ -329,7 +329,7 @@ impl AnyNode {
| AnyNode::ExprCompare(_)
| AnyNode::ExprCall(_)
| AnyNode::FormattedValue(_)
| AnyNode::StringTodoName(_)
| AnyNode::PartialString(_)
| AnyNode::ExprFString(_)
| AnyNode::ExprConstant(_)
| AnyNode::ExprAttribute(_)
Expand Down Expand Up @@ -423,7 +423,7 @@ impl AnyNode {
| AnyNode::ExprCompare(_)
| AnyNode::ExprCall(_)
| AnyNode::FormattedValue(_)
| AnyNode::StringTodoName(_)
| AnyNode::PartialString(_)
| AnyNode::ExprFString(_)
| AnyNode::ExprConstant(_)
| AnyNode::ExprAttribute(_)
Expand Down Expand Up @@ -502,7 +502,7 @@ impl AnyNode {
| AnyNode::ExprCompare(_)
| AnyNode::ExprCall(_)
| AnyNode::FormattedValue(_)
| AnyNode::StringTodoName(_)
| AnyNode::PartialString(_)
| AnyNode::ExprFString(_)
| AnyNode::ExprConstant(_)
| AnyNode::ExprAttribute(_)
Expand Down Expand Up @@ -606,7 +606,7 @@ impl AnyNode {
Self::ExprCompare(node) => AnyNodeRef::ExprCompare(node),
Self::ExprCall(node) => AnyNodeRef::ExprCall(node),
Self::FormattedValue(node) => AnyNodeRef::FormattedValue(node),
Self::StringTodoName(node) => AnyNodeRef::StringTodoName(node),
Self::PartialString(node) => AnyNodeRef::PartialString(node),
Self::ExprFString(node) => AnyNodeRef::ExprFString(node),
Self::ExprConstant(node) => AnyNodeRef::ExprConstant(node),
Self::ExprAttribute(node) => AnyNodeRef::ExprAttribute(node),
Expand Down Expand Up @@ -2601,20 +2601,20 @@ impl AstNode for ast::FormattedValue {
}
}
}
impl AstNode for ast::StringTodoName {
impl AstNode for ast::PartialString {
fn cast(kind: AnyNode) -> Option<Self>
where
Self: Sized,
{
if let AnyNode::StringTodoName(node) = kind {
if let AnyNode::PartialString(node) = kind {
Some(node)
} else {
None
}
}

fn cast_ref(kind: AnyNodeRef) -> Option<&Self> {
if let AnyNodeRef::StringTodoName(node) = kind {
if let AnyNodeRef::PartialString(node) = kind {
Some(node)
} else {
None
Expand Down Expand Up @@ -4404,9 +4404,9 @@ impl From<ast::FormattedValue> for AnyNode {
}
}

impl From<ast::StringTodoName> for AnyNode {
fn from(node: ast::StringTodoName) -> Self {
AnyNode::StringTodoName(node)
impl From<ast::PartialString> for AnyNode {
fn from(node: ast::PartialString) -> Self {
AnyNode::PartialString(node)
}
}

Expand Down Expand Up @@ -4645,7 +4645,7 @@ impl Ranged for AnyNode {
AnyNode::ExprCompare(node) => node.range(),
AnyNode::ExprCall(node) => node.range(),
AnyNode::FormattedValue(node) => node.range(),
AnyNode::StringTodoName(node) => node.range(),
AnyNode::PartialString(node) => node.range(),
AnyNode::ExprFString(node) => node.range(),
AnyNode::ExprConstant(node) => node.range(),
AnyNode::ExprAttribute(node) => node.range(),
Expand Down Expand Up @@ -4731,7 +4731,7 @@ pub enum AnyNodeRef<'a> {
ExprCompare(&'a ast::ExprCompare),
ExprCall(&'a ast::ExprCall),
FormattedValue(&'a ast::FormattedValue),
StringTodoName(&'a ast::StringTodoName),
PartialString(&'a ast::PartialString),
ExprFString(&'a ast::ExprFString),
ExprConstant(&'a ast::ExprConstant),
ExprAttribute(&'a ast::ExprAttribute),
Expand Down Expand Up @@ -4816,7 +4816,7 @@ impl AnyNodeRef<'_> {
AnyNodeRef::ExprCompare(node) => NonNull::from(*node).cast(),
AnyNodeRef::ExprCall(node) => NonNull::from(*node).cast(),
AnyNodeRef::FormattedValue(node) => NonNull::from(*node).cast(),
AnyNodeRef::StringTodoName(node) => NonNull::from(*node).cast(),
AnyNodeRef::PartialString(node) => NonNull::from(*node).cast(),
AnyNodeRef::ExprFString(node) => NonNull::from(*node).cast(),
AnyNodeRef::ExprConstant(node) => NonNull::from(*node).cast(),
AnyNodeRef::ExprAttribute(node) => NonNull::from(*node).cast(),
Expand Down Expand Up @@ -4907,7 +4907,7 @@ impl AnyNodeRef<'_> {
AnyNodeRef::ExprCompare(_) => NodeKind::ExprCompare,
AnyNodeRef::ExprCall(_) => NodeKind::ExprCall,
AnyNodeRef::FormattedValue(_) => NodeKind::FormattedValue,
AnyNodeRef::StringTodoName(_) => NodeKind::StringTodoName,
AnyNodeRef::PartialString(_) => NodeKind::PartialString,
AnyNodeRef::ExprFString(_) => NodeKind::ExprFString,
AnyNodeRef::ExprConstant(_) => NodeKind::ExprConstant,
AnyNodeRef::ExprAttribute(_) => NodeKind::ExprAttribute,
Expand Down Expand Up @@ -4993,7 +4993,7 @@ impl AnyNodeRef<'_> {
| AnyNodeRef::ExprCompare(_)
| AnyNodeRef::ExprCall(_)
| AnyNodeRef::FormattedValue(_)
| AnyNodeRef::StringTodoName(_)
| AnyNodeRef::PartialString(_)
| AnyNodeRef::ExprFString(_)
| AnyNodeRef::ExprConstant(_)
| AnyNodeRef::ExprAttribute(_)
Expand Down Expand Up @@ -5090,7 +5090,7 @@ impl AnyNodeRef<'_> {
| AnyNodeRef::StmtIpyEscapeCommand(_)
| AnyNodeRef::ExceptHandlerExceptHandler(_)
| AnyNodeRef::FormattedValue(_)
| AnyNodeRef::StringTodoName(_)
| AnyNodeRef::PartialString(_)
| AnyNodeRef::PatternMatchValue(_)
| AnyNodeRef::PatternMatchSingleton(_)
| AnyNodeRef::PatternMatchSequence(_)
Expand Down Expand Up @@ -5164,7 +5164,7 @@ impl AnyNodeRef<'_> {
| AnyNodeRef::ExprCompare(_)
| AnyNodeRef::ExprCall(_)
| AnyNodeRef::FormattedValue(_)
| AnyNodeRef::StringTodoName(_)
| AnyNodeRef::PartialString(_)
| AnyNodeRef::ExprFString(_)
| AnyNodeRef::ExprConstant(_)
| AnyNodeRef::ExprAttribute(_)
Expand Down Expand Up @@ -5258,7 +5258,7 @@ impl AnyNodeRef<'_> {
| AnyNodeRef::ExprCompare(_)
| AnyNodeRef::ExprCall(_)
| AnyNodeRef::FormattedValue(_)
| AnyNodeRef::StringTodoName(_)
| AnyNodeRef::PartialString(_)
| AnyNodeRef::ExprFString(_)
| AnyNodeRef::ExprConstant(_)
| AnyNodeRef::ExprAttribute(_)
Expand Down Expand Up @@ -5337,7 +5337,7 @@ impl AnyNodeRef<'_> {
| AnyNodeRef::ExprCompare(_)
| AnyNodeRef::ExprCall(_)
| AnyNodeRef::FormattedValue(_)
| AnyNodeRef::StringTodoName(_)
| AnyNodeRef::PartialString(_)
| AnyNodeRef::ExprFString(_)
| AnyNodeRef::ExprConstant(_)
| AnyNodeRef::ExprAttribute(_)
Expand Down Expand Up @@ -5450,7 +5450,7 @@ impl AnyNodeRef<'_> {
AnyNodeRef::ExprCompare(node) => node.visit_preorder(visitor),
AnyNodeRef::ExprCall(node) => node.visit_preorder(visitor),
AnyNodeRef::FormattedValue(node) => node.visit_preorder(visitor),
AnyNodeRef::StringTodoName(node) => node.visit_preorder(visitor),
AnyNodeRef::PartialString(node) => node.visit_preorder(visitor),
AnyNodeRef::ExprFString(node) => node.visit_preorder(visitor),
AnyNodeRef::ExprConstant(node) => node.visit_preorder(visitor),
AnyNodeRef::ExprAttribute(node) => node.visit_preorder(visitor),
Expand Down Expand Up @@ -5765,9 +5765,9 @@ impl<'a> From<&'a ast::FormattedValue> for AnyNodeRef<'a> {
}
}

impl<'a> From<&'a ast::StringTodoName> for AnyNodeRef<'a> {
fn from(node: &'a ast::StringTodoName) -> Self {
AnyNodeRef::StringTodoName(node)
impl<'a> From<&'a ast::PartialString> for AnyNodeRef<'a> {
fn from(node: &'a ast::PartialString) -> Self {
AnyNodeRef::PartialString(node)
}
}

Expand Down Expand Up @@ -6118,7 +6118,7 @@ impl Ranged for AnyNodeRef<'_> {
AnyNodeRef::ExprCompare(node) => node.range(),
AnyNodeRef::ExprCall(node) => node.range(),
AnyNodeRef::FormattedValue(node) => node.range(),
AnyNodeRef::StringTodoName(node) => node.range(),
AnyNodeRef::PartialString(node) => node.range(),
AnyNodeRef::ExprFString(node) => node.range(),
AnyNodeRef::ExprConstant(node) => node.range(),
AnyNodeRef::ExprAttribute(node) => node.range(),
Expand Down Expand Up @@ -6206,7 +6206,7 @@ pub enum NodeKind {
ExprCompare,
ExprCall,
FormattedValue,
StringTodoName,
PartialString,
ExprFString,
ExprConstant,
ExprAttribute,
Expand Down
8 changes: 4 additions & 4 deletions crates/ruff_python_ast/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ pub struct FormattedValue {
}

#[derive(Clone, Debug, PartialEq)]
pub struct StringTodoName {
pub struct PartialString {
pub range: TextRange,
pub value: String,
}
Expand Down Expand Up @@ -875,7 +875,7 @@ impl From<ExprFString> for Expr {

#[derive(Clone, Debug, PartialEq)]
pub enum FStringPart {
String(StringTodoName),
Literal(PartialString),
FormattedValue(FormattedValue),
}

Expand Down Expand Up @@ -3078,13 +3078,13 @@ impl Ranged for crate::nodes::FormattedValue {
impl Ranged for crate::nodes::FStringPart {
fn range(&self) -> TextRange {
match self {
FStringPart::String(node) => node.range(),
FStringPart::Literal(node) => node.range(),
FStringPart::FormattedValue(node) => node.range(),
}
}
}

impl Ranged for crate::nodes::StringTodoName {
impl Ranged for crate::nodes::PartialString {
fn range(&self) -> TextRange {
self.range
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_python_ast/src/relocate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ pub fn relocate_expr(expr: &mut Expr, location: TextRange) {
/// location.
fn relocate_fstring_part(part: &mut nodes::FStringPart, location: TextRange) {
match part {
nodes::FStringPart::String(nodes::StringTodoName { range, .. }) => {
nodes::FStringPart::Literal(nodes::PartialString { range, .. }) => {
*range = location;
}
nodes::FStringPart::FormattedValue(nodes::FormattedValue {
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_python_codegen/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ impl<'a> Generator<'a> {

fn unparse_fstring_elem(&mut self, part: &ast::FStringPart) {
match part {
ast::FStringPart::String(ast::StringTodoName { value, .. }) => {
ast::FStringPart::Literal(ast::PartialString { value, .. }) => {
self.unparse_fstring_literal(value);
}
ast::FStringPart::FormattedValue(ast::FormattedValue {
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_python_formatter/src/expression/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<'a> AnyString<'a> {
let string_content = locator.slice(*range);
string_content.contains(['"', '\''])
}
ast::FStringPart::String(_) => false,
ast::FStringPart::Literal(_) => false,
}) {
Quoting::Preserve
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ expression: parse_ast
range: 0..14,
implicit_concatenated: false,
parts: [
String(
StringTodoName {
Literal(
PartialString {
range: 2..13,
value: "Hello world",
},
Expand Down
Loading

0 comments on commit 0f3ac34

Please sign in to comment.