python / python/mypy

`str-format` for fill and align specifiers

Offen
#18,800 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

feature
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Feature

The fill and align string format specifiers do not currently have type checking, but are not supported by all types. Specifically, None does not support them.

Pitch

I ran into a bug where an optional type was being passed to string formatting using <. This would succeed most of the time, but error if the value was None:

>>> "{:<2}".format(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported format string passed to NoneType.__format__

It would be great if mypy would catch this code as a type violation.

I attempted to implement here: https://github.com/python/mypy/pull/18799 but this was more challenging than I anticipated and I am a first time contributor.

Thanks.

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

Überprüfe zuerst die versuchte Implementierung in PR #18799 und verfolge anschließend, wie mypy die Typprüfung von Formatspezifizierern für Füll- und Ausrichtungsspezifizierer behandelt. Fertig ist die Aufgabe, wenn mypy einen Fehler meldet, sobald ein optionaler Wert wie None mit einem nicht unterstützten Füll- oder Ausrichtungsspezifizierer formatiert wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
devtools
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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