Remove duplicate code by making `traceback.print_list()` delegate to `format_list()`
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 1/5
- Geschätzter Aufwand
- Unter einer Stunde
- Anfängerfreundlichkeit
- 25/100
Rechercherichtung
Beginne in Lib/traceback.py, indem du die Einstiegspunkte print_list() und format_list() sowie deren aktuelle Formatierungspfade vergleichst. Erledigt ist die Aufgabe, wenn print_list() an format_list() delegiert, ohne die Ausgabe oder die Dateiverarbeitung zu ändern; der Issue verweist auf PR gh-153783, prüfe daher diese Arbeit, bevor du fortfährst.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
In Lib/traceback.py, the public helpers print_list() and format_list() independently contain the same formatting expression, so their outputs agree only by duplication. We propose routing print_list() through format_list() so that they share a single formatting path, with no change in behavior.
Problem
format_list() returns the formatted lines:
def format_list(extracted_list):
return StackSummary.from_list(extracted_list).format()
print_list() writes those same lines, but re-derives them with the identical expression instead of reusing format_list():
def print_list(extracted_list, file=None):
if file is None:
file = sys.stderr
for item in StackSummary.from_list(extracted_list).format():
print(item, file=file, end="")
The outputs match only because StackSummary.from_list(extracted_list).format() is duplicated in both. Any future change to how a frame list is formatted has to be applied in both places to prevent the two public helpers from silently diverging.
Solution
Have print_list() iterate format_list():
def print_list(extracted_list, file=None):
if file is None:
file = sys.stderr
for item in format_list(extracted_list):
print(item, file=file, end="")
This eliminates the possibility of drift and mirrors the delegation already used in this module; for example, print_tb() calls print_list() rather than re-deriving extract_tb(...).format().
Linked PRs
- gh-153783
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 36k
- Ø Merge
- 1 T. 9 Std.
- Gemergte PRs (30 T.)
- 558
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python/cpython
-
docs pending
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
stdlib type-feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
stdlib type-feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
build type-bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
-
stdlib topic-email type-feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Ähnliche Issues
-
link-check link-check:sphinx-theme
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
OpenHands/extensions#626 · 1 Kommentar ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
CSCfi/sd-search-api#39 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100