python / python/cpython

Better `repr` for `string.templatelib.Template`.

Offen
#151,099 6 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

interpreter-core type-feature
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Feature or enhancement

Proposal:

Currently the repr output for template strings shows how the data is stored internally, but this is not how the template could be reconstructed via an constructor call and the format is unintuitive since the template parts are not output in the order they appear in the template source. The repr result should output the parts in the order as iterating over the template object does, i.e.

x = 1
y = 2
print(repr(t'{x} + {y}'))

should print

Template(Interpolation(1, 'x', None, ''), ' + ', Interpolation(2, 'y', None, ''))

instead of

Template(strings=('', ' + ', ''), interpolations=(Interpolation(1, 'x', None, ''), Interpolation(2, 'y', None, '')))

This has already been discussed at https://discuss.python.org/t/repr-output-of-t-strings/107653

I'm working on a patch/pull request.

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/repr-output-of-t-strings/107653

Linked PRs
  • gh-151104

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem im Issue beschriebenen repr-Verhalten von string.templatelib.Template und vergleiche es mit der Iteration über ein Template-Objekt. Überprüfe, dass repr die Template-Teile in Iterationsreihenfolge ausgibt und dem vorgeschlagenen Format eines Konstruktoraufrufs entspricht; gh-151104 ist verknüpft, daher prüfe diese Arbeit, bevor du beginnst.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
backend
Issue-Typ
Feature
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.