Title: Typing: runtime-checkable protocols are broken on `main` · Issue #104555 · python/cpython · GitHub
Open Graph Title: Typing: runtime-checkable protocols are broken on `main` · Issue #104555 · python/cpython
X Title: Typing: runtime-checkable protocols are broken on `main` · Issue #104555 · python/cpython
Description: 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 typing import Protocol, runtime_checkable, TypeVar >>> T_co = TypeVar("T_co", covariant=True) >...
Open Graph Description: 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 typing import Protocol, runtime_checkable, TypeVar >>> ...
X Description: 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 typing import Protocol, runtime_checka...
Opengraph URL: https://github.com/python/cpython/issues/104555
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Typing: runtime-checkable protocols are broken on `main`","articleBody":"PEP-695 protocols don't work as intended:\r\n\r\nHere's the behaviour you get with protocols that use pre-PEP 695 syntax, which is correct:\r\n\r\n```pycon\r\n\u003e\u003e\u003e from typing import Protocol, runtime_checkable, TypeVar\r\n\u003e\u003e\u003e T_co = TypeVar(\"T_co\", covariant=True)\r\n\u003e\u003e\u003e @runtime_checkable\r\n... class SupportsAbsOld(Protocol[T_co]):\r\n... def __abs__(self) -\u003e T_co:\r\n... ...\r\n...\r\n\u003e\u003e\u003e isinstance(0, SupportsAbsOld)\r\nTrue\r\n\u003e\u003e\u003e issubclass(float, SupportsAbsOld)\r\nTrue\r\n```\r\n\r\nAnd here's the behaviour you get on `main` with protocols that use PEP 695 syntax, which is incorrect:\r\n\r\n```pycon\r\n\u003e\u003e\u003e @runtime_checkable\r\n... class SupportsAbsNew[T_co](Protocol):\r\n... def __abs__(self) -\u003e T_co:\r\n... ...\r\n...\r\n\u003e\u003e\u003e isinstance(0, SupportsAbsNew)\r\nFalse\r\n\u003e\u003e\u003e issubclass(float, SupportsAbsNew)\r\nTraceback (most recent call last):\r\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\r\n File \"C:\\Users\\alexw\\coding\\cpython\\Lib\\abc.py\", line 123, in __subclasscheck__\r\n return _abc_subclasscheck(cls, subclass)\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n File \"C:\\Users\\alexw\\coding\\cpython\\Lib\\typing.py\", line 1875, in _proto_hook\r\n raise TypeError(\"Protocols with non-method members\"\r\nTypeError: Protocols with non-method members don't support issubclass()\r\n```\r\n\r\n\u003c!-- gh-linked-prs --\u003e\r\n### Linked PRs\r\n* gh-104556\r\n* gh-104559\n\u003c!-- /gh-linked-prs --\u003e\r\n","author":{"url":"https://github.com/AlexWaygood","@type":"Person","name":"AlexWaygood"},"datePublished":"2023-05-16T15:22:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":23},"url":"https://github.com/104555/cpython/issues/104555"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b161f33a-0b6c-e100-0587-3248ebbc364c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AB22:2DA0A8:9363EF:C5F7F8:6969BF56 |
| html-safe-nonce | 6a5b6958a3608620e7fc58df26344008f463521e16b22d367ac7afc7ee4c4638 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQjIyOjJEQTBBODo5MzYzRUY6QzVGN0Y4OjY5NjlCRjU2IiwidmlzaXRvcl9pZCI6IjcwOTAxMDgxODk4MjE3NDcwMzAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c96e527c7b597e6c5ede632e4f765253efca7e6fc612c7b7e8c2558495775a04 |
| hovercard-subject-tag | issue:1712247778 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/104555/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3f1b8c6dfa46d1e7112e51b976b56c1073e9e45d118af52a737217e5778387ea/python/cpython/issues/104555 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3f1b8c6dfa46d1e7112e51b976b56c1073e9e45d118af52a737217e5778387ea/python/cpython/issues/104555 |
| og:image:alt | 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 typing import Protocol, runtime_checkable, TypeVar >>> ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AlexWaygood |
| hostname | github.com |
| expected-hostname | github.com |
| None | acedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 83c08c21cdda978090dc44364b71aa5bc6dcea79 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width