Title: __slots__ and protocols don't work right for `issubclass` and typevar bounds · Issue #11884 · python/mypy · GitHub
Open Graph Title: __slots__ and protocols don't work right for `issubclass` and typevar bounds · Issue #11884 · python/mypy
X Title: __slots__ and protocols don't work right for `issubclass` and typevar bounds · Issue #11884 · python/mypy
Description: cc @sobolevn since you've been doing stuff here Bug Report Slots become part of a interface with protocols, they shouldn't be. To Reproduce import typing @typing.runtime_checkable class Foo(typing.Protocol): __slots__ = () class Bar: pas...
Open Graph Description: cc @sobolevn since you've been doing stuff here Bug Report Slots become part of a interface with protocols, they shouldn't be. To Reproduce import typing @typing.runtime_checkable class Foo(typing....
X Description: cc @sobolevn since you've been doing stuff here Bug Report Slots become part of a interface with protocols, they shouldn't be. To Reproduce import typing @typing.runtime_checkable class Foo...
Opengraph URL: https://github.com/python/mypy/issues/11884
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"__slots__ and protocols don't work right for `issubclass` and typevar bounds","articleBody":"cc @sobolevn since you've been doing stuff here\r\n\r\n**Bug Report**\r\n\r\nSlots become part of a interface with protocols, they shouldn't be.\r\n\r\n**To Reproduce**\r\n\r\n```py\r\nimport typing\r\n\r\n@typing.runtime_checkable\r\nclass Foo(typing.Protocol):\r\n __slots__ = ()\r\n\r\n\r\nclass Bar:\r\n pass\r\n\r\n_T = typing.TypeVar(\"_T\", bound=\"Foo\")\r\n\r\n\r\ndef foo(f: _T) -> _T:\r\n return f\r\n\r\nprint(issubclass(Bar, Foo))\r\nprint(isinstance(Bar(), Foo))\r\nfoo(Bar())\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nAt runtime this prints:\r\n```\r\nTrue\r\nTrue\r\n```\r\n\r\nSo issubclass is allowed, and I don't see why the TypeVar bounds shouldn't be.\r\n\r\n**Actual Behavior**\r\n\r\n```\r\nmain.py:17: error: Only protocols that don't have non-method members can be used with issubclass()\r\nmain.py:17: note: Protocol \"Foo\" has non-method member(s): __slots__\r\nmain.py:19: error: Value of type variable \"_T\" of \"foo\" cannot be \"Bar\"\r\nFound 2 errors in 1 file (checked 1 source file)\r\n```\r\n\r\n**Your Environment**\r\n\r\n[mypy playground](https://mypy-play.net/?mypy=latest&python=3.10&gist=46508246c59701af4ba8ad0d4dc4a596)","author":{"url":"https://github.com/A5rocks","@type":"Person","name":"A5rocks"},"datePublished":"2022-01-02T03:21:24Z","url":"https://github.com/python/mypy/issues/11884"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:e56bad28-e718-b23a-8837-e74e379eef23 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A1EA:5537E:1DECAA6:27931F8:6B003459 |
| html-safe-nonce | 8636eb0c8f6b8ea9df2f98c0934e7bc772a5b3f0bafdb85c8db51f375e1be456 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMUVBOjU1MzdFOjFERUNBQTY6Mjc5MzFGODo2QjAwMzQ1OSIsInZpc2l0b3JfaWQiOiI0Mzc2Mzc3NjU1NTY2NTQ2MDA5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3843d0488a197b051375ff83abe8d3427d4306b6e9b3330a0eae8ee13f77ec84 |
| hovercard-subject-tag | issue:1091941677 |
| 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/mypy/11884/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c40f9e94cc074c58cdb5ae52e8ea13d4c118ef80c7ae875285f7fbb613f23df8/python/mypy/issues/11884 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c40f9e94cc074c58cdb5ae52e8ea13d4c118ef80c7ae875285f7fbb613f23df8/python/mypy/issues/11884 |
| og:image:alt | cc @sobolevn since you've been doing stuff here Bug Report Slots become part of a interface with protocols, they shouldn't be. To Reproduce import typing @typing.runtime_checkable class Foo(typing.... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | A5rocks |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width