Title: [1.12 regression] mypy no longer recognises descriptors/get that bind self · Issue #18036 · python/mypy · GitHub
Open Graph Title: [1.12 regression] mypy no longer recognises descriptors/get that bind self · Issue #18036 · python/mypy
X Title: [1.12 regression] mypy no longer recognises descriptors/get that bind self · Issue #18036 · python/mypy
Description: Bug Report For decorators that work on methods as descriptors, I do type-hint+overload __get__ as returning the descriptor or filling in self. This previously worked up to MyPy 1.11 and PyRight was/is happy with it. However, since versio...
Open Graph Description: Bug Report For decorators that work on methods as descriptors, I do type-hint+overload __get__ as returning the descriptor or filling in self. This previously worked up to MyPy 1.11 and PyRight was...
X Description: Bug Report For decorators that work on methods as descriptors, I do type-hint+overload __get__ as returning the descriptor or filling in self. This previously worked up to MyPy 1.11 and PyRight was...
Opengraph URL: https://github.com/python/mypy/issues/18036
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[1.12 regression] mypy no longer recognises descriptors/get that bind self","articleBody":"**Bug Report**\r\n\r\nFor decorators that work on methods as descriptors, I do type-hint+overload `__get__` as returning the descriptor or filling in `self`. This previously worked up to MyPy 1.11 and PyRight was/is happy with it. However, since version 1.12 MyPy no longer matches the overload and completely loses type information; the `Possible overload variant` suggested is the least suitable.\r\n\r\nI initially [was notified about this](https://github.com/maxfischer2781/asyncstdlib/issues/161) for [my own library providing `async` versions of the standard library, specifically the `lru_cache`](https://github.com/maxfischer2781/asyncstdlib/blob/0cdd850f3ef221020a178fd4b34a095b423f0781/asyncstdlib/_lrucache.pyi#L34-L49). An MRE not using my library is below (in case I missed something that makes the MRE fixable but not my library, this would be good to know, too).\r\n\r\n**To Reproduce**\r\n\r\n```python\r\nfrom __future__ import annotations\r\nfrom typing import Any, overload, Callable, Concatenate\r\n\r\n\r\nclass Descriptor[C: Callable[..., Any]]:\r\n def __init__(self, impl: C) -> None: ...\r\n\r\n @overload\r\n def __get__(\r\n self: Descriptor[C], instance: None, owner: type | None\r\n ) -> Descriptor[C]: ...\r\n\r\n @overload\r\n def __get__[S, **P, R](\r\n self: Descriptor[Callable[Concatenate[S, P], R]], instance: S, owner: type | None,\r\n ) -> Callable[P, R]: ...\r\n\r\n\r\nclass Test:\r\n @Descriptor\r\n def method(self, foo: int, bar: str) -> bytes: ...\r\n\r\n\r\nreveal_type(Test().method)\r\n# Pyright pyright 1.1.386 Type of \"Test().method\" is \"(foo: int, bar: str) -> bytes\"\r\n# MyPy 1.11 Revealed type is \"def (foo: builtins.int, bar: builtins.str) -> builtins.bytes\"\r\n# MyPy 1.12 Revealed type is \"Any\"\r\n```\r\n\r\n[Playground link.](https://mypy-play.net/?mypy=latest&python=3.12&gist=5503735d0ff9d5af1a979bdf441ed38c&enable-incomplete-feature=NewGenericSyntax) The ordering of the `overload` cases does not matter.\r\n\r\n**Expected Behavior**\r\n\r\nMyPy should correctly infer the type of the bound method. MyPy should report the most suitable overload.\r\n\r\n**Actual Behavior**\r\n\r\nMyPy matches none of the overloads and thus completely loses type information. The reported most suitable overload is actually the least suitable.\r\n\r\n**Your Environment**\r\n\r\n\u003c!-- Include as many relevant details about the environment you experienced the bug in -->\r\n\r\n- Mypy version used: 1.12 and 1.13\r\n- Mypy command-line flags: None\r\n- Mypy configuration options from `mypy.ini` (and other config files): defaults\r\n- Python version used: CPython 3.8 - 3.12\r\n\r\n\u003c!-- You can freely edit this text, please remove all the lines you believe are unnecessary. -->\r\n","author":{"url":"https://github.com/maxfischer2781","@type":"Person","name":"maxfischer2781"},"datePublished":"2024-10-24T18:54:09Z","url":"https://github.com/python/mypy/issues/18036"}
| 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:af3c3ac8-a379-47f7-7717-12b26c504172 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 88F0:37BEAD:22682CE:2EE8556:6B002A55 |
| html-safe-nonce | f6368add07c1383cc7746467d1099c35ed5579e8acb1a0ac2abd844ff9ef60df |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OEYwOjM3QkVBRDoyMjY4MkNFOjJFRTg1NTY6NkIwMDJBNTUiLCJ2aXNpdG9yX2lkIjoiMTcyNTM5MzE1MzIxMDQ2MDc1NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a36f242c03d953f992cd1fba7a4978412da47038e808ecd80086b67c07cdc64e |
| hovercard-subject-tag | issue:2612340026 |
| 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/18036/issue_layout |
| twitter:image | https://opengraph.githubassets.com/880c223491042dd72424e3304486de8c3a60c353c96e0ad4bfb83a38f1bc1680/python/mypy/issues/18036 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/880c223491042dd72424e3304486de8c3a60c353c96e0ad4bfb83a38f1bc1680/python/mypy/issues/18036 |
| og:image:alt | Bug Report For decorators that work on methods as descriptors, I do type-hint+overload __get__ as returning the descriptor or filling in self. This previously worked up to MyPy 1.11 and PyRight was... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | maxfischer2781 |
| 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