Title: Change in inference of overloads involving `Hashable` and `slice` now that `slice` is generic · Issue #18149 · python/mypy · GitHub
Open Graph Title: Change in inference of overloads involving `Hashable` and `slice` now that `slice` is generic · Issue #18149 · python/mypy
X Title: Change in inference of overloads involving `Hashable` and `slice` now that `slice` is generic · Issue #18149 · python/mypy
Description: Bug Report Consider the following Python snippet, saved as foo.pyi: from typing import assert_type, overload, Hashable class Foo: ... class DataFrame: @overload def __getitem__(self, key: slice) -> DataFrame: ... @overload def __getitem_...
Open Graph Description: Bug Report Consider the following Python snippet, saved as foo.pyi: from typing import assert_type, overload, Hashable class Foo: ... class DataFrame: @overload def __getitem__(self, key: slice) ->...
X Description: Bug Report Consider the following Python snippet, saved as foo.pyi: from typing import assert_type, overload, Hashable class Foo: ... class DataFrame: @overload def __getitem__(self, key: slice) -&...
Opengraph URL: https://github.com/python/mypy/issues/18149
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Change in inference of overloads involving `Hashable` and `slice` now that `slice` is generic","articleBody":"**Bug Report**\r\n\r\nConsider the following Python snippet, saved as `foo.pyi`:\r\n\r\n```py\r\nfrom typing import assert_type, overload, Hashable\r\n\r\nclass Foo: ...\r\n\r\nclass DataFrame:\r\n @overload\r\n def __getitem__(self, key: slice) -> DataFrame: ...\r\n @overload\r\n def __getitem__(self, key: Hashable) -> Foo: ...\r\n\r\n\r\ndf = DataFrame()\r\nassert_type(df[1:], DataFrame)\r\nassert_type(df[:2], DataFrame)\r\n```\r\n\r\nPrior to [the recent change to make `slice` generic in typeshed](https://github.com/python/typeshed/pull/11637), mypy used to emit no errors on this snippet. However, mypy on the `master` branch emits the following errors:\r\n\r\n```\r\nfoo.pyi:7: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [overload-overlap]\r\nfoo.pyi:13: error: Expression is of type \"Any\", not \"DataFrame\" [assert-type]\r\nfoo.pyi:14: error: Expression is of type \"Any\", not \"DataFrame\" [assert-type]\r\n```\r\n\r\nThe first error here seems reasonable to me, but it's unclear to me why mypy now infers `Any` as the result of the `df` subscriptions. This snippet is minimized from the sole new mypy_primer error reported in https://github.com/python/typeshed/pull/11637#issuecomment-2435268577.\r\n\r\n**To Reproduce**\r\n\r\nhttps://mypy-play.net/?mypy=master&python=3.12&gist=339ba7f72c9048770ce15d6dc75207a1\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: mypy 1.14.0+dev.2ebc690279c7e20ed8bec006787030c5ba57c40e (compiled: no)\r\n","author":{"url":"https://github.com/AlexWaygood","@type":"Person","name":"AlexWaygood"},"datePublished":"2024-11-12T18:19:58Z","url":"https://github.com/python/mypy/issues/18149"}
| 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:533656c6-0f1c-5e00-b80c-755c761c639a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A05C:1A2F85:E75AB2:1376BE6:6B005810 |
| html-safe-nonce | e1df633720472030c0e025d21526080e0ab87497f4c7e25e05182f50bb09c1d0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDVDOjFBMkY4NTpFNzVBQjI6MTM3NkJFNjo2QjAwNTgxMCIsInZpc2l0b3JfaWQiOiI4MTY3OTM1NTE1NTg5MzY3ODI0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | bd0ae1f23080193828444b34d4cc99d4a381eb388930db0af14826b4459e83eb |
| hovercard-subject-tag | issue:2652970002 |
| 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/18149/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f416f5bbb1f663b90a1785d88a5e1570255f03774496d3b46c30e0691b4c4c29/python/mypy/issues/18149 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f416f5bbb1f663b90a1785d88a5e1570255f03774496d3b46c30e0691b4c4c29/python/mypy/issues/18149 |
| og:image:alt | Bug Report Consider the following Python snippet, saved as foo.pyi: from typing import assert_type, overload, Hashable class Foo: ... class DataFrame: @overload def __getitem__(self, key: slice) ->... |
| 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 | 29be975efff6507a5d135de9c7d634cf7ff8f0c55222a64386ab3202209aaf73 |
| 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 | eacd927ba6112e3b01ba99c762bd699a4a4f5df7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width