ruff/crates/ruff_python_ast/src
Dhruv Manilawala 5f40371ffc
Use ExprFString for StringLike::FString variant (#10311)
## Summary

This PR updates the `StringLike::FString` variant to use `ExprFString`
instead of `FStringLiteralElement`.

For context, the reason it used `FStringLiteralElement` is that the node
is actually the string part of an f-string ("foo" in `f"foo{x}"`). But,
this is inconsistent with other variants where the captured value is the
_entire_ string.

This is also problematic w.r.t. implicitly concatenated strings. Any
rules which work with `StringLike::FString` doesn't account for the
string part in an implicitly concatenated f-strings. For example, we
don't flag confusable character in the first part of `"𝐁ad" f"𝐁ad
string"`, but only the second part
(https://play.ruff.rs/16071c4c-a1dd-4920-b56f-e2ce2f69c843).

### Update `PYI053`

_This is included in this PR because otherwise it requires a temporary
workaround to be compatible with the old logic._

This PR also updates the `PYI053` (`string-or-bytes-too-long`) rule for
f-string to consider _all_ the visible characters in a f-string,
including the ones which are implicitly concatenated. This is consistent
with implicitly concatenated strings and bytes.

For example,

```python
def foo(
	# We count all the characters here
    arg1: str = '51 character ' 'stringgggggggggggggggggggggggggggggggg',
	# But not here because of the `{x}` replacement field which _breaks_ them up into two chunks
    arg2: str = f'51 character {x} stringgggggggggggggggggggggggggggggggggggggggggggg',
) -> None: ...
```

This PR fixes it to consider all _visible_ characters inside an f-string
which includes expressions as well.

fixes: #10310 
fixes: #10307 

## Test Plan

Add new test cases and update the snapshots.

## Review

To facilitate the review process, the change have been split into two
commits: one which has the code change while the other has the test
cases and updated snapshots.
2024-03-14 13:30:22 +05:30
..
visitor Remove Expr postfix from ExprNamed, ExprIf, and ExprGenerator (#10229) 2024-03-04 12:55:01 +01:00
all.rs Remove Expr postfix from ExprNamed, ExprIf, and ExprGenerator (#10229) 2024-03-04 12:55:01 +01:00
comparable.rs Remove Expr postfix from ExprNamed, ExprIf, and ExprGenerator (#10229) 2024-03-04 12:55:01 +01:00
docstrings.rs Move Python whitespace utilities into new ruff_python_whitespace crate (#4993) 2023-06-10 00:59:57 +00:00
expression.rs Use ExprFString for StringLike::FString variant (#10311) 2024-03-14 13:30:22 +05:30
hashable.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
helpers.rs Remove Expr postfix from ExprNamed, ExprIf, and ExprGenerator (#10229) 2024-03-04 12:55:01 +01:00
identifier.rs Update to Rust 1.74 and use new clippy lints table (#8722) 2023-11-16 18:12:46 -05:00
imports.rs Use Rust 1.75 toolchain (#9437) 2024-01-08 18:03:16 +01:00
int.rs Include radix base prefix in large number representation (#7700) 2023-09-28 20:38:06 +00:00
lib.rs Split CallPath into QualifiedName and UnqualifiedName (#10210) 2024-03-04 09:06:51 +00:00
name.rs refactor: Use QualifiedName for Imported::call_path (#10214) 2024-03-06 09:55:59 +01:00
node.rs Start tracking quoting style in the AST (#10298) 2024-03-08 19:11:47 +00:00
nodes.rs Unify enums used for internal representation of quoting style (#10383) 2024-03-13 17:19:17 +00:00
parenthesize.rs Comments outside expression parentheses (#7873) 2023-10-19 09:24:11 +00:00
relocate.rs Remove Expr postfix from ExprNamed, ExprIf, and ExprGenerator (#10229) 2024-03-04 12:55:01 +01:00
statement_visitor.rs Remove Stmt::TryStar (#6566) 2023-08-14 13:39:44 -04:00
stmt_if.rs Misc. small tweaks from perusing modules (#9383) 2024-01-03 12:30:25 -05:00
str.rs Unify enums used for internal representation of quoting style (#10383) 2024-03-13 17:19:17 +00:00
traversal.rs [flake8-simplify] Implement enumerate-for-loop (SIM113) (#7777) 2024-01-14 11:00:59 -05:00
types.rs Remove RefEquality (#6393) 2023-08-07 16:04:50 +00:00
visitor.rs Remove Expr postfix from ExprNamed, ExprIf, and ExprGenerator (#10229) 2024-03-04 12:55:01 +01:00
whitespace.rs Use consistent re-export from ruff_source_file (#9320) 2023-12-30 14:48:45 -05:00