parser: cpython parser bug in template strings t'{0!=0:}'
Abierto
@lysnikolaou ya está trabajando en esto.
Desde el 29/3/2026.
3.14
3.15
interpreter-core
topic-parser
type-bug
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Bug report
Bug description:
There is an bug in the parser for template strings when the expression contains a ! like in !=.
The value is parsed correct but the str attribute contains only the part before the !.
bug
>>> import ast
>>> print(ast.dump(ast.parse("t'{0!=0:}'"),indent=2))
Module(
body=[
Expr(
value=TemplateStr(
values=[
Interpolation(
value=Compare(
left=Constant(value=0),
ops=[
NotEq()],
comparators=[
Constant(value=0)]),
str='0', # <- this should be 0!=0
conversion=-1,
format_spec=JoinedStr())]))])
>>> print(ast.dump(ast.parse("t'{0!=0:s}'"),indent=2))
Module(
body=[
Expr(
value=TemplateStr(
values=[
Interpolation(
value=Compare(
left=Constant(value=0),
ops=[
NotEq()],
comparators=[
Constant(value=0)]),
str='0', # <- same here
conversion=-1,
format_spec=JoinedStr(
values=[
Constant(value='s')]))]))])
correct
>>> import ast
>>> print(ast.dump(ast.parse("t'{0!=0}'"),indent=2))
Module(
body=[
Expr(
value=TemplateStr(
values=[
Interpolation(
value=Compare(
left=Constant(value=0),
ops=[
NotEq()],
comparators=[
Constant(value=0)]),
str='0!=0',
conversion=-1)]))])
>>> print(ast.dump(ast.parse("t'{0==0:}'"),indent=2))
Module(
body=[
Expr(
value=TemplateStr(
values=[
Interpolation(
value=Compare(
left=Constant(value=0),
ops=[
Eq()],
comparators=[
Constant(value=0)]),
str='0==0',
conversion=-1,
format_spec=JoinedStr())]))])
I must also share the credit with Claude, who is currently in charge of developing pysource-codegen.
CPython versions tested on:
3.14, 3.15
Operating systems tested on:
No response
Linked PRs
- gh-146614
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Evaluación
Este issue todavía no se ha evaluado.