Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
The AST unparsing ofInterpolation objects does not reproduce formatting within interpolations.
This is true both forast.unparse in Python:
>>> ast.unparse(ast.parse('t"{a + b}"'))"t'{a + b}'"And for the C unparse that is used byfrom __future__ import annotations:
>>> ns = {}>>> exec("""... from __future__ import annotations... def f(x: t"{a + b}"): ...... """, ns)>>> ns["f"].__annotations__{'x': "t'{a + b}'"}In general, we can't recover the original source exactly, but in this case we do have the original source available:
>>> ast.parse('t"{a + b}"').body[0].value.values[0].str'a + b'Let's use it.
CPython versions tested on:
3.14
Operating systems tested on:
No response