python / python/cpython

Changed behavior of singledispatch in Python 3.12

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

@AlexWaygood đang làm issue này rồi.

Từ ngày 20/3/2024.

3.12 3.13 stdlib topic-typing type-bug
Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Bug report

Bug description:

It seems the behavior of functools.singledispatch changed in Python 3.12 in situations where a typing.Protocol is involved.

When executing the following code on 3.12, MyClass no longer gets dispatched as via the default but as MyProtocol. The problem seems to be that issubclass now behaves differently when called on protocols. The issue was noticed here where it caused downstream problems.

from typing import Protocol
from functools import singledispatch


class MyProtocol(Protocol):
    pass

class MyClass:
    pass

s = singledispatch(lambda x: "default")
s.register(MyProtocol, lambda x: "protocol")

print(s(MyClass))  # yields "default" on 3.11 but "protocol" on 3.12
CPython versions tested on:

3.11, 3.12

Operating systems tested on:

macOS

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.

Đánh giá

Issue này chưa được đánh giá.

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.