ruff/crates/ruff_python_formatter/resources/test/fixtures/ruff
Dylan 008bbfdf5a
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
Disallow implicit concatenation of t-strings and other string types (#19485)
As of [this cpython PR](https://github.com/python/cpython/pull/135996),
it is not allowed to concatenate t-strings with non-t-strings,
implicitly or explicitly. Expressions such as `"foo" t"{bar}"` are now
syntax errors.

This PR updates some AST nodes and parsing to reflect this change.

The structural change is that `TStringPart` is no longer needed, since,
as in the case of `BytesStringLiteral`, the only possibilities are that
we have a single `TString` or a vector of such (representing an implicit
concatenation of t-strings). This removes a level of nesting from many
AST expressions (which is what all the snapshot changes reflect), and
simplifies some logic in the implementation of visitors, for example.

The other change of note is in the parser. When we meet an implicit
concatenation of string-like literals, we now count the number of
t-string literals. If these do not exhaust the total number of
implicitly concatenated pieces, then we emit a syntax error. To recover
from this syntax error, we encode any t-string pieces as _invalid_
string literals (which means we flag them as invalid, record their
range, and record the value as `""`). Note that if at least one of the
pieces is an f-string we prefer to parse the entire string as an
f-string; otherwise we parse it as a string.

This logic is exactly the same as how we currently treat
`BytesStringLiteral` parsing and error recovery - and carries with it
the same pros and cons.

Finally, note that I have not implemented any changes in the
implementation of the formatter. As far as I can tell, none are needed.
I did change a few of the fixtures so that we are always concatenating
t-strings with t-strings.
2025-07-27 12:41:03 +00:00
..
carriage_return Normalize '\r' in string literals to '\n' 2023-06-30 10:13:23 +02:00
expression Disallow implicit concatenation of t-strings and other string types (#19485) 2025-07-27 12:41:03 +00:00
fmt_on_off Spellcheck & grammar (#10375) 2024-03-13 02:34:23 +00:00
fmt_skip Allow # fmt: skip with interspersed same-line comments (#9395) 2024-01-04 19:39:37 -05:00
parentheses Comments outside expression parentheses (#7873) 2023-10-19 09:24:11 +00:00
pattern Preserve tuple parentheses in case patterns (#18147) 2025-05-22 07:52:21 +02:00
range_formatting Ruff 2025 style guide (#13906) 2025-01-09 10:20:06 +01:00
statement Use ast::PythonVersion internally in the formatter and linter (#16170) 2025-02-18 12:03:13 -05:00
stub_files [formatter] Fix missing blank lines before decorated classes in .pyi files (#18888) 2025-06-24 16:25:44 +02:00
.editorconfig Fix \r and \r\n handling in t- and f-string debug texts (#18673) 2025-06-15 06:53:06 +01:00
blank_line_before_class_docstring.options.json Implement no_blank_line_before_class_docstring preview style (#9154) 2023-12-19 00:43:20 -06:00
blank_line_before_class_docstring.py Implement no_blank_line_before_class_docstring preview style (#9154) 2023-12-19 00:43:20 -06:00
docstring.options.json Use double quotes for all docstrings, including single-quoted docstrings (#9020) 2023-12-07 04:41:00 +00:00
docstring.py Spellcheck & grammar (#10375) 2024-03-13 02:34:23 +00:00
docstring_chaperones.py Don't add chaperone space after escaped quote in triple quote (#17216) 2025-04-11 10:21:47 +02:00
docstring_code_examples.options.json ruff_python_formatter: implement "dynamic" line width mode for docstring code formatting (#9098) 2023-12-12 09:58:07 -05:00
docstring_code_examples.py Fix typos found by codespell (#9346) 2024-01-02 02:08:15 +00:00
docstring_code_examples_crlf.options.json format doctests in docstrings (#8811) 2023-11-27 11:14:55 -05:00
docstring_code_examples_crlf.py format doctests in docstrings (#8811) 2023-11-27 11:14:55 -05:00
docstring_code_examples_dynamic_line_width.options.json ruff_python_formatter: implement "dynamic" line width mode for docstring code formatting (#9098) 2023-12-12 09:58:07 -05:00
docstring_code_examples_dynamic_line_width.py Fix codeblock dynamic line length calculation for indented examples (#13523) 2024-09-27 09:09:07 +02:00
docstring_newlines.py Don't trim last empty line in docstrings (#9813) 2024-02-05 13:29:24 +00:00
docstring_non_visible_characters.py Fix typos found by codespell (#14863) 2024-12-09 09:32:12 +00:00
docstring_tab_indentation.options.json Docstring formatting: Preserve tab indentation when using indent-style=tabs (#9915) 2024-02-12 16:09:13 +01:00
docstring_tab_indentation.py Docstring formatting: Preserve tab indentation when using indent-style=tabs (#9915) 2024-02-12 16:09:13 +01:00
empty_multiple_trailing_newlines.py Fix handling of newlines in empty files (#7473) 2023-09-18 06:08:10 +00:00
empty_now_newline.py Fix handling of newlines in empty files (#7473) 2023-09-18 06:08:10 +00:00
empty_trailing_newline.py Fix handling of newlines in empty files (#7473) 2023-09-18 06:08:10 +00:00
empty_whitespace.py Fix handling of newlines in empty files (#7473) 2023-09-18 06:08:10 +00:00
f-string-carriage-return-newline.py Fix \r and \r\n handling in t- and f-string debug texts (#18673) 2025-06-15 06:53:06 +01:00
form_feed.py Treat form feed as whitespace in SimpleTokenizer (#7626) 2023-09-25 14:34:59 +00:00
module_dangling_comment1.py Format empty lines in stub files like black's preview style (#7206) 2023-09-11 08:03:59 +00:00
module_dangling_comment2.py Format empty lines in stub files like black's preview style (#7206) 2023-09-11 08:03:59 +00:00
multiline_string_deviations.py Hug multiline-strings preview style (#9243) 2024-01-10 12:47:34 +01:00
newlines.py Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
newlines.pyi Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
notebook_docstring.options.json Disable top-level docstring formatting for notebooks (#9957) 2024-02-12 18:14:02 +00:00
notebook_docstring.py Disable top-level docstring formatting for notebooks (#9957) 2024-02-12 18:14:02 +00:00
pattern_match_regression_brackets.py Preserve tuple parentheses in case patterns (#18147) 2025-05-22 07:52:21 +02:00
preview.options.json Add test and basic implementation for formatter preview mode (#8044) 2023-10-26 15:33:26 +00:00
preview.py Add test and basic implementation for formatter preview mode (#8044) 2023-10-26 15:33:26 +00:00
quote_style.options.json Add "preserve" quote-style to mimic Black's skip-string-normalization (#8822) 2023-12-07 23:59:22 +00:00
quote_style.py Preview Style: Format module level docstring (#9725) 2024-02-05 15:03:34 +00:00
skip_magic_trailing_comma.options.json Add tests for skip magic trailing comma 2023-06-26 14:15:55 +02:00
skip_magic_trailing_comma.py Improve with statement comment handling and expression breaking (#6621) 2023-08-18 03:30:38 +00:00
tab_width.options.json Introduce IndentWidth (#7301) 2023-09-13 14:52:24 +02:00
tab_width.py Introduce IndentWidth (#7301) 2023-09-13 14:52:24 +02:00
trailing_comments.py Treat ty: comments as pragma comments (#18532) 2025-06-07 16:02:43 +02:00
trivia.py Use pass over ellipsis in non-function/class contexts (#8049) 2023-10-19 11:11:17 +02:00