Add stubs for stdlib `_colorize` module

Aberta Para iniciantes
#16,361 2 comentários 1 reação 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
72/100
Tipo de issue
Funcionalidade
Clareza
Razoavelmente clara
Status de atividade
Ativa
Stack de tecnologia
python
Domínio
tooling

Direção de pesquisa

Comece lendo Lib/_colorize.py do CPython e compare suas definições tipadas com os stubs da biblioteca padrão em typeshed. Verifique o exemplo reveal_type fornecido com pyright, pyrefly e ty; considera-se concluído quando os nomes e as assinaturas de _colorize são reconhecidos de forma consistente e sem erros.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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

Linguagem predominante
Python
Estrelas
5.1k
Forks
2.1k
Merge médio
1d 13h
PRs com merge (30d)
73

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de python/typeshed

Todas as issues de python/typeshed

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.