mirror of
https://github.com/astral-sh/ruff.git
synced 2025-12-23 09:19:58 +00:00
[ty] Respect debug text interpolation in f-strings (#22151)
## Summary Per @carljm's comment, we just fall back to `str`. Closes https://github.com/astral-sh/ty/issues/2151.
This commit is contained in:
parent
06db474f20
commit
4745d15fff
2 changed files with 15 additions and 2 deletions
|
|
@ -24,6 +24,16 @@ string = "hello"
|
|||
reveal_type(f"{string!r}") # revealed: str
|
||||
```
|
||||
|
||||
## Debug Specifier
|
||||
|
||||
The `=` specifier causes the expression text and value to be included in the output:
|
||||
|
||||
```py
|
||||
# f"{1=}" evaluates to "1=1", but we fall back to `str` for now
|
||||
reveal_type(f"{1=}") # revealed: str
|
||||
reveal_type(f"value: {42=}") # revealed: str
|
||||
```
|
||||
|
||||
## Format Specifiers
|
||||
|
||||
```py
|
||||
|
|
|
|||
|
|
@ -7594,7 +7594,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
|||
range: _,
|
||||
node_index: _,
|
||||
expression,
|
||||
debug_text: _,
|
||||
debug_text,
|
||||
conversion,
|
||||
format_spec,
|
||||
} = expression;
|
||||
|
|
@ -7613,7 +7613,10 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
|||
// (`Type::format`?) that handles the `__format__` method.
|
||||
// Conversion flags should be handled before calling `__format__`.
|
||||
// https://docs.python.org/3/library/string.html#format-string-syntax
|
||||
if !conversion.is_none() || format_spec.is_some() {
|
||||
if debug_text.is_some()
|
||||
|| !conversion.is_none()
|
||||
|| format_spec.is_some()
|
||||
{
|
||||
collector.add_expression();
|
||||
} else {
|
||||
if let Type::StringLiteral(literal) = ty.str(self.db()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue