Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Support `Any` as an alias for `object` to describe a default typeclass implementation

Đang mở
#307 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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

Đánh giá

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

Hướng nghiên cứu

Issue không nêu tên các tệp triển khai hoặc các bài kiểm thử. Hãy bắt đầu bằng cách tìm phần xử lý phía sau @render.instance(object) và các bài kiểm thử instance của typeclass hiện có, sau đó lần theo cách object default được nhận diện. Được xem là hoàn tất khi @render.instance(Any) hoạt động tương đương với @render.instance(object), trong khi ví dụ dispatch implementation fallback.

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

Mô tả

Context. In order to define a default implementation (the one used if no other implementation matches), we currently have to write something like this:

from classes import typeclass

@typeclass
def render(data_value) -> str:
    """Render a data value nicely."""

@render.instance(int)
def _render_int(data_value: int) -> str:
    return f'This is an integer: {data_value}'


@render.instance(object)
def _render_int(data_value: object) -> str:
    return f'No idea what this is: {data_value}'


assert render('BADOOM') == 'No idea what this is: BADOOM'

(this script should be runnable as-is.)

Decision. Support Any as a special case to replace object:

@render.instance(Any)
def _render_int(data_value: Any) -> str:    # type: ignore
    return f'No idea what this is: {data_value}'

Consequences.

  • Pro: The code will look a little bit more straightforward;
  • Contra: mypy with common settings might be unhappy about Any being used, but that can be silenced with type: ignore I suppose.
Ngôn ngữ chính
Python
Star
730
Fork
30
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

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.

Issue khác của dry-python/classes

Tất cả issue của dry-python/classes

Issue tương tự

Thêm issue về Python

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.