python / python/cpython

certain f/t-string expressions not copied correctly to debug str or interpolations

Aperta
#141,271 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

3.14 3.15 interpreter-core topic-parser type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug report

Bug description:

The function set_ftstring_expr() in Parser/lexer/lexer.c does not currently copy certain f/t-string expressions correctly. It has problems with non-coding quotes (escaped or in comments) and nested f/t-strings. This applies to both self-documenting debug expressions and more importantly to t-string interpolation expressions.

For example, the # comment below should not print:

>>> print(f'''{'\'' # comment
... =}''')
'\'' # comment
="'"

Copied expression terminates early:

>>> print(f'{(f'''
... # not comment A
... { # comment B '
... 3 # comment C
... * 2}''', '\n# not comment D\n6')=}')
(f'''
# not comment A
{ # comment B '
3
* 2}''', '\n('\n# not comment A\n6', '\n# not comment D\n6')

It does not appear the function was written to handle nested f/t-strings and the string quote handling does not take into account escaped quotes.

CPython versions tested on:

3.14, CPython main branch

Operating systems tested on:

Linux

Linked PRs
  • gh-141274

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in Parser/lexer/lexer.c, in set_ftstring_expr(), e riproduci gli esempi del report con virgolette con escape, commenti e f/t-string annidate. Traccia il modo in cui le espressioni vengono copiate per l’output di debug e l’interpolazione delle t-string, quindi verifica che il testo tra virgolette e i commenti non interrompano la copia in anticipo e che gli output mostrati siano corretti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
c
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.