Title: Cryptic error message for two generic callables with different variable binding · Issue #17551 · python/mypy · GitHub
Open Graph Title: Cryptic error message for two generic callables with different variable binding · Issue #17551 · python/mypy
X Title: Cryptic error message for two generic callables with different variable binding · Issue #17551 · python/mypy
Description: Bug Report If a @contextmanager yields a generic type alias, mypy 1.11 errors with Argument 1 to "contextmanager" has incompatible type "$TYPE"; expected "$TYPE" [arg-type], where the inferred and expected types are identical. This does ...
Open Graph Description: Bug Report If a @contextmanager yields a generic type alias, mypy 1.11 errors with Argument 1 to "contextmanager" has incompatible type "$TYPE"; expected "$TYPE" [arg-type], where the inferred and ...
X Description: Bug Report If a @contextmanager yields a generic type alias, mypy 1.11 errors with Argument 1 to "contextmanager" has incompatible type "$TYPE"; expected "$TYPE" [arg-...
Opengraph URL: https://github.com/python/mypy/issues/17551
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cryptic error message for two generic callables with different variable binding","articleBody":"**Bug Report**\r\n\r\nIf a `@contextmanager` yields a generic type alias, mypy 1.11 errors with `Argument 1 to \"contextmanager\" has incompatible type \"$TYPE\"; expected \"$TYPE\" [arg-type]`, where the inferred and expected types are identical.\r\n\r\nThis does not happen if the generic type is inlined (no type alias), or if the type alias is not generic; see playground link below for examples.\r\n\r\nThis started happening in 1.11 (didn't happen in 1.10). This may be related to https://github.com/python/mypy/issues/8696, but I opened a new issue because it looks like a regression.\r\n\r\nReal code that tripped this: [link](https://github.com/lemon24/reader/blob/6df7892507ed4996f354f9a0a33e35c9c06e9053/src/reader/_utils.py#L89-L128).\r\n\r\n\r\n**To Reproduce**\r\n\r\nShort version (more examples in playground links below):\r\n\r\n```python\r\nGenericFn = Callable[[_T], _T]\r\n\r\n@contextmanager\r\ndef make_generic() -> Iterator[GenericFn[_T]]:\r\n def rv(obj: _T) -> _T:\r\n return obj\r\n yield rv\r\n```\r\n\r\nPlayground:\r\n\r\n* [1.11.0](https://mypy-play.net/?mypy=1.11.0&python=3.12&gist=f52c95a6ce272f6ea3f333a4bd8345bd) fails\r\n* [1.10.1](https://mypy-play.net/?mypy=1.10.1&python=3.12&gist=f52c95a6ce272f6ea3f333a4bd8345bd) succeeds\r\n\r\n\r\n**Expected Behavior**\r\n\r\nEither fail with a useful error message (the inferred and expected types being exactly the same is confusing; I am not sure what would fix the error), or don't fail (like 1.10).\r\n\r\n\r\n**Actual Behavior**\r\n\r\n```\r\nerror: Argument 1 to \"contextmanager\" has incompatible type \"Callable[[], Iterator[Callable[[_T], _T]]]\"; expected \"Callable[[], Iterator[Callable[[_T], _T]]]\" [arg-type]\r\n```\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 1.11.0\r\n- Mypy command-line flags: --strict\r\n- Mypy configuration options from `mypy.ini` (and other config files): n/a\r\n- Python version used: 3.12\r\n","author":{"url":"https://github.com/lemon24","@type":"Person","name":"lemon24"},"datePublished":"2024-07-21T11:14:20Z","url":"https://github.com/python/mypy/issues/17551"}
| 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:a4752399-563e-bcc2-3c7c-7be2d93b8fde |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9EA4:B0403:10A13DF:15BED72:6AFFFB97 |
| html-safe-nonce | 4c30f723ad2ba4413e9f66c55aada5bea19c65b569b7ad4a7e86816cf76c038b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RUE0OkIwNDAzOjEwQTEzREY6MTVCRUQ3Mjo2QUZGRkI5NyIsInZpc2l0b3JfaWQiOiI4OTA2MjI2ODM4ODU0OTU3OTc1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7ff2e47d6121bddc11c5313967f2644900f6418e54209038c1f2d0ce5c6ad9b4 |
| hovercard-subject-tag | issue:2421352472 |
| 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/17551/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2632e49af1b8af415b8a83b26cfc9f1f6a34e502dd2c4a35bc1aa0740a76b5da/python/mypy/issues/17551 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2632e49af1b8af415b8a83b26cfc9f1f6a34e502dd2c4a35bc1aa0740a76b5da/python/mypy/issues/17551 |
| og:image:alt | Bug Report If a @contextmanager yields a generic type alias, mypy 1.11 errors with Argument 1 to "contextmanager" has incompatible type "$TYPE"; expected "$TYPE" [arg-type], where the inferred and ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lemon24 |
| 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