GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||
GeezerVison is showing github.com — Strange interaction between `typing.Protocol` and unrelated `isinstance()` checks · Issue #105144 · python/cpython Closed Labels 3.12only security fixesonly security fixes3.13only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionOn >>> from typing import Sized >>> isinstance(1, Sized) False However! If you first subclass >>> from typing import Sized, Protocol >>> class Foo(Sized, Protocol): pass ... >>> isinstance(1, Sized) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\alexw\coding\cpython\Lib\typing.py", line 1153, in __instancecheck__ return self.__subclasscheck__(type(obj)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\alexw\coding\cpython\Lib\typing.py", line 1428, in __subclasscheck__ return issubclass(cls, self.__origin__) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen abc>", line 123, in __subclasscheck__ File "C:\Users\alexw\coding\cpython\Lib\typing.py", line 1793, in __subclasscheck__ return super().__subclasscheck__(other) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen abc>", line 123, in __subclasscheck__ File "C:\Users\alexw\coding\cpython\Lib\typing.py", line 1876, in _proto_hook raise TypeError("Instance and class checks can only be used with" TypeError: Instance and class checks can only be used with @runtime_checkable protocols This was originally reported by @vnmabus in python/typing_extensions#207. Note that (because of the >>> import typing >>> isinstance(1, typing.Sized) False >>> class Foo(typing.Sized, typing.Protocol): pass ... >>> isinstance(1, typing.Sized) False Linked PRs
Activity
MetadataMetadataAssigneesLabels3.12only security fixesonly security fixes3.13only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error ProjectsMilestoneRelationshipsDevelopmentIssue actions | ||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |