python / python/typeshed

Add stubs for stdlib `_colorize` module

Ouverte Adaptée aux débutants
#16,361 2 commentaires 1 réaction 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
Python
Étoiles
5.1k
Forks
2.1k
Merge moyen
1 j 19 h
PR mergées (30 j)
82

Description

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par lire Lib/_colorize.py de CPython et comparez ses définitions typées avec les stubs de la bibliothèque standard dans typeshed. Vérifiez l’exemple reveal_type fourni avec pyright, pyrefly et ty ; c’est terminé lorsque les noms et les signatures de _colorize sont reconnus de manière cohérente et sans erreurs.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
tooling
Type d'issue
Fonctionnalité
Difficulté
2/5
Temps estimé
1-3 heures
Activité
Active
Clarté
Plutôt claire
Accessibilité débutants
72/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.