Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Typing: runtime-checkable protocols are broken onmain #104555

Assignees
JelleZijlstraAlexWaygood
Labels
@AlexWaygood

Description

@AlexWaygood

PEP-695 protocols don't work as intended:

Here's the behaviour you get with protocols that use pre-PEP 695 syntax, which is correct:

>>>from typingimport Protocol, runtime_checkable, TypeVar>>> T_co= TypeVar("T_co",covariant=True)>>>@runtime_checkable...classSupportsAbsOld(Protocol[T_co]):...def__abs__(self) -> T_co:.........>>>isinstance(0, SupportsAbsOld)True>>>issubclass(float, SupportsAbsOld)True

And here's the behaviour you get onmain with protocols that use PEP 695 syntax, which is incorrect:

>>>@runtime_checkable...class SupportsAbsNew[T_co](Protocol):...def__abs__(self) -> T_co:.........>>>isinstance(0, SupportsAbsNew)False>>>issubclass(float, SupportsAbsNew)Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "C:\Users\alexw\coding\cpython\Lib\abc.py", line 123, in __subclasscheck__    return _abc_subclasscheck(cls, subclass)           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "C:\Users\alexw\coding\cpython\Lib\typing.py", line 1875, in _proto_hook    raise TypeError("Protocols with non-method members"TypeError: Protocols with non-method members don't support issubclass()

Linked PRs

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp