python / python/typeshed

Add stubs for stdlib `_colorize` module

Offen Anfängerfreundlich
#16,361 2 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
5.1k
Forks
2.1k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
82

Beschreibung

Description

_colorize was introduced in 3.13, and has been steadily growing since then.

From (https://github.com/python/cpython/issues/133346), I got the impression that the naming is due to unfortunate timing:

Rename _colorize to colorize

There's frankly very little time for this before Python 3.14 beta 1. I would rather keep the library name underscored for 3.14 and gather feedback from the community on the format and behavior, and introduce a stable API in Python 3.15, keeping _colorize for backward compatibility.

Interestingly, _colorize is already fully-typed (https://github.com/python/cpython/blob/main/Lib/_colorize.py).
I'm here because the absence in _typeshed means this example [^1] can produce errors in some type checkers:

[^1]: Adapted from a comment in _colorize

from typing import reveal_type

try:
    from _colorize import ANSIColors, Syntax, default_theme, set_theme
except ImportError:
    pass
else:
    reveal_type(set_theme)
    theme_with_dim_operators = default_theme.copy_with(syntax=Syntax(op=ANSIColors.INTENSE_BLACK))
    set_theme(theme_with_dim_operators)
    del set_theme, default_theme, Syntax, ANSIColors, theme_with_dim_operators

This checks out fine with pyright, but both pyrefly and ty seem to not know about _colorize yet.
Perhaps adding to typeshed would help?

Related

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 damit, CPythons Lib/_colorize.py zu lesen, und vergleiche seine typisierten Definitionen mit den Stubs der Standardbibliothek in typeshed. Prüfe das bereitgestellte reveal_type-Beispiel mit pyright, pyrefly und ty; als erledigt gilt die Aufgabe, wenn die _colorize-Namen und -Signaturen von allen drei Tools konsistent und ohne Fehler erkannt werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Aktiv
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
72/100

Neue Issues direkt in Ihr Postfach

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