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

Behaviour change in py312 for protocols with non-callable members and custom__subclasshook__ methods #105974

Closed
Assignees
AlexWaygood
Labels
3.12only security fixes3.13bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error
@AlexWaygood

Description

@AlexWaygood

Bug report

On Python 3.11:

>>>from typingimport*>>>@runtime_checkable...classFoo(Protocol):...     x=1...@classmethod...def__subclasshook__(cls,other):...returnhasattr(other,'x')...>>>issubclass(object, Foo)False

On Python 3.12:

>>>from typingimport*>>>@runtime_checkable...classFoo(Protocol):...     x=1...@classmethod...def__subclasshook__(cls,other):...return hsattr(cls,'x')...>>>issubclass(object, Foo)Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "C:\Users\alexw\coding\cpython\Lib\typing.py", line 1829, in __subclasscheck__    raise TypeError(TypeError: Protocols with non-method members don't support issubclass()

I think I prefer the Python 3.11 behaviour here, since the whole point of allowing protocols to define custom__subclasshook__ methods is so that users can customise howissubclass() works on user-defined protocols.

Linked PRs

Metadata

Metadata

Assignees

Labels

3.12only security fixes3.13bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp