Title: Builtin classes have a register method, because of Protocol inheritance · Issue #13466 · python/typeshed · GitHub
Open Graph Title: Builtin classes have a register method, because of Protocol inheritance · Issue #13466 · python/typeshed
X Title: Builtin classes have a register method, because of Protocol inheritance · Issue #13466 · python/typeshed
Description: Builtin classes str and list inherit from Sequence and indirectly from Protocol, which implies that register is available for those classes, which is not correct. In Python it is possible to use register on a Protocol, but not on str: >>...
Open Graph Description: Builtin classes str and list inherit from Sequence and indirectly from Protocol, which implies that register is available for those classes, which is not correct. In Python it is possible to use re...
X Description: Builtin classes str and list inherit from Sequence and indirectly from Protocol, which implies that register is available for those classes, which is not correct. In Python it is possible to use re...
Opengraph URL: https://github.com/python/typeshed/issues/13466
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Builtin classes have a register method, because of Protocol inheritance","articleBody":"Builtin classes `str` and `list` inherit from `Sequence` and indirectly from `Protocol`, which implies that `register` is available for those classes, which is not correct.\n\nIn Python it is possible to use `register` on a Protocol, but not on `str`:\n\n```\n>>> from typing import Protocol\n>>> class Foo(Protocol):\n... x: str\n... \n>>> Foo.register(int)\n\u003cclass 'int'>\n>>> str.register(int)\nTraceback (most recent call last):\n File \"\u003cstdin>\", line 1, in \u003cmodule>\nAttributeError: type object 'str' has no attribute 'register'\n```\n\nIn Mypy it is valid to use `register` on Protocols, but it's also possible to write `str.register(int)` or `list.register(int)`, which is incorrect.\n\nIn Pyright `register` doesn't work on all protocols:\n\n```\nfrom typing import Protocol\nlist.register(int) # Doesn't work (which is correct)\n\nclass Foo(Protocol):\n x: str\n\nFoo.register(int) # Also doesn't work (but it should)\n```\n\nSo it feels that both Mypy and Pyright are not correct here and typeshed itself doesn't really help. I feel it is kind of wrong that `str` and `list` inherit from Protocols, but I can understand that it reduces a lot of duplicate code in stubs. Is there another way how we could improve this situation? Should we add a marker for those cases where a class inherits from a Protocol in typeshed, but is not really a Protocol during runtime?","author":{"url":"https://github.com/davidhalter","@type":"Person","name":"davidhalter"},"datePublished":"2025-02-05T22:12:28Z","url":"https://github.com/python/typeshed/issues/13466"}
| 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:35588c1c-b0c9-8b25-edd6-8e4a596bebd6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 81E0:308D9D:1BF8DBA:25E94B1:6B0007C2 |
| html-safe-nonce | aa813d2f06c3a6f36529d31077ac8d98fc92a181fe5fda5b932531c94ace325a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MUUwOjMwOEQ5RDoxQkY4REJBOjI1RTk0QjE6NkIwMDA3QzIiLCJ2aXNpdG9yX2lkIjoiMzUwMTg3NTc5NTMxMDE1MTYxOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5497a4c025cb07444961067fa85f1d9f2c0bc5a7ee51297360b0ccf65117e195 |
| hovercard-subject-tag | issue:2834065636 |
| 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/typeshed/13466/issue_layout |
| twitter:image | https://opengraph.githubassets.com/209df620df2e4410c985ce514d121309830fa994c7c6348e49709d007a26b818/python/typeshed/issues/13466 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/209df620df2e4410c985ce514d121309830fa994c7c6348e49709d007a26b818/python/typeshed/issues/13466 |
| og:image:alt | Builtin classes str and list inherit from Sequence and indirectly from Protocol, which implies that register is available for those classes, which is not correct. In Python it is possible to use re... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | davidhalter |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typeshed git https://github.com/python/typeshed.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 31696383 |
| octolytics-dimension-repository_nwo | python/typeshed |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31696383 |
| octolytics-dimension-repository_network_root_nwo | python/typeshed |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width