Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions crates/codegen/src/unparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,19 +628,7 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
// put a space to avoid escaping the bracket
"{ "
} else {
// Preserve leading whitespace between '{' and the expression
let source_text = self.source.source_text();
let start = val.range().start().to_usize();
if start > 0
&& source_text
.as_bytes()
.get(start - 1)
.is_some_and(|b| b.is_ascii_whitespace())
{
"{ "
} else {
"{"
}
"{"
};
self.p(brace)?;
self.p(&buffered)?;
Expand Down
13 changes: 13 additions & 0 deletions extra_tests/snippets/syntax_annotations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
from typing import get_type_hints

# Future f-string annotations canonicalize fields, not their literal padding.
for formatted, expected in (

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove the disallowed regression-test additions

This loop adds new test data, compilation logic, and an assertion to extra_tests/snippets/syntax_annotations.py, but the root AGENTS.md says that the only acceptable test-file edits are adding expected-failure decorators or removing them with their TODOs. Please remove these additions or get the repository policy changed or waived before landing the implementation.

AGENTS.md reference: AGENTS.md:L277-L279

Useful? React with 👍 / 👎.

("f'{ value }'", "f'{value}'"),
("f'{ value = }'", "f' value = {value!r}'"),
("f'{ value : >8}'", "f'{value: >8}'"),
("f'{ {1, 2} }'", "f'{ {1, 2}}'"),
):
formatted_code = compile(
"from __future__ import annotations\nx: " + formatted, "<test>", "exec"
)
assert expected in formatted_code.co_consts


def func(s: str) -> int:
return int(s)

Expand Down
Loading