Message362691
Most usual usecase for format_spec is to specify it as a constant, that would be logical to represent as ast.Constant. However, ast.parse wraps value of ast.FormattedValue.format_spec into a JoinedStr with a single constant value, as can be seen from example below:
import ast
code = '''f"is {x:d}"'''
tree = ast.parse(code)
for n in ast.walk(tree):
if isinstance(n, ast.FormattedValue):
print(
type(n.format_spec),
len(n.format_spec.values),
set(type(v) for v in n.format_spec.values),
)
This is confusing for programmatically analyzing the ast, and likely creates some overhead in any modules using ast and FormattedValue.
Proposal: represent ast.FormattedValue.format_spec as ast.Constant in most cases. |
|
Date |
User |
Action |
Args |
2020-02-26 12:43:03 | Ilya Kamenshchikov | set | recipients:
+ Ilya Kamenshchikov |
2020-02-26 12:43:02 | Ilya Kamenshchikov | set | messageid: <1582720982.96.0.367799860574.issue39760@roundup.psfhosted.org> |
2020-02-26 12:43:02 | Ilya Kamenshchikov | link | issue39760 messages |
2020-02-26 12:43:02 | Ilya Kamenshchikov | create | |
|