python / python/typeshed

Add stubs for stdlib `_colorize` module

Đang mở Phù hợp với người mới
#16,361 2 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Python
Star
5.1k
Fork
2.1k
Merge trung bình
1 ngày 19 giờ
Pull request đã merge (30 ngày)
82

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách đọc Lib/_colorize.py của CPython và so sánh các định nghĩa có kiểu của nó với các stub của thư viện chuẩn trong typeshed. Kiểm tra ví dụ reveal_type được cung cấp bằng pyright, pyrefly và ty; hoàn tất khi các tên và chữ ký của _colorize được nhận diện nhất quán mà không có lỗi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
tooling
Loại issue
Tính năng
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
72/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.