Title: Ordering matters for @overload · Issue #1270 · python/mypy · GitHub
Open Graph Title: Ordering matters for @overload · Issue #1270 · python/mypy
X Title: Ordering matters for @overload · Issue #1270 · python/mypy
Description: I am trying to model a generic container (a Pandas Series though it shouldn't matter too much for this). The container has a generic "value type" and a generic "index type". When iterating over the container, you get the value type back....
Open Graph Description: I am trying to model a generic container (a Pandas Series though it shouldn't matter too much for this). The container has a generic "value type" and a generic "index type". When iterating over the...
X Description: I am trying to model a generic container (a Pandas Series though it shouldn't matter too much for this). The container has a generic "value type" and a generic "index type"....
Opengraph URL: https://github.com/python/mypy/issues/1270
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Ordering matters for @overload","articleBody":"I am trying to model a generic container (a [Pandas Series](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.html) though it shouldn't matter too much for this). The container has a generic \"value type\" and a generic \"index type\". When iterating over the container, you get the value type back. So I tried with:\n\n``` python\nclass Series(Generic[VT, IT], Sequence[VT]):\n\n @overload\n def __getitem__(self, key: slice) -> List[VT]: ...\n\n @overload\n def __getitem__(self, key: int) -> VT: ...\n```\n\nThis gives me an error:\n\n```\nstubs/pandas/__init__.pyi: note: In class \"Series\":\nstubs/pandas/__init__.pyi:186: error: Signature of \"__getitem__\" incompatible with supertype \"Sequence\"\n```\n\nThat baffled me for a while and on a whim, I tried reordering the two signatures:\n\n``` python\nclass Series(Generic[VT, IT], Sequence[VT]):\n\n @overload\n def __getitem__(self, key: int) -> VT: ...\n\n @overload\n def __getitem__(self, key: slice) -> List[VT]: ...\n```\n\nThe error is now gone! :-)\n\nWhen I first got the error, I tried going into `typing.py` to see exactly what signature Sequence has. That didn't help me since Sequence is defined as\n\n``` python\nclass Sequence(Sized, Iterable[T_co], Container[T_co],\n extra=collections_abc.Sequence):\n pass\n```\n\nI think it could have been helpful if mypy could have written the exact types it was comparing.\n\nThis was tested with 0ec0cb4.\n","author":{"url":"https://github.com/mgeisler","@type":"Person","name":"mgeisler"},"datePublished":"2016-03-04T09:08:38Z","url":"https://github.com/python/mypy/issues/1270"}
| 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:7f505baa-742d-a4eb-f44e-7ca991eb7fe3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D640:1833B7:1A44E22:234F324:6AFFFB94 |
| html-safe-nonce | ab5050875b1c4abaf365cf733f7cb61c4564faa4a14175f20d4fc3fe1f0d3ba3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENjQwOjE4MzNCNzoxQTQ0RTIyOjIzNEYzMjQ6NkFGRkZCOTQiLCJ2aXNpdG9yX2lkIjoiMjU2OTUxNTk1Mzg2Nzk3OTY2OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 05c238f4125223c9f73f0516c04823b5e05d7d1d66088797773180c8cfadf43b |
| hovercard-subject-tag | issue:138421820 |
| 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/1270/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8291bf9d02b480861ab5ddbe39e8a222df74b51a428b1647182f8ae1753b82cb/python/mypy/issues/1270 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8291bf9d02b480861ab5ddbe39e8a222df74b51a428b1647182f8ae1753b82cb/python/mypy/issues/1270 |
| og:image:alt | I am trying to model a generic container (a Pandas Series though it shouldn't matter too much for this). The container has a generic "value type" and a generic "index type". When iterating over the... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mgeisler |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width