Title: Bug - Type aliases in closure does not work · Issue #8273 · python/mypy · GitHub
Open Graph Title: Bug - Type aliases in closure does not work · Issue #8273 · python/mypy
X Title: Bug - Type aliases in closure does not work · Issue #8273 · python/mypy
Description: This may be a known limitation of the type system, but it would be nice if it were possible to write the following without the commented error: from typing import Any, Callable, Type, TypeVar from threading import Lock F = TypeVar("F", b...
Open Graph Description: This may be a known limitation of the type system, but it would be nice if it were possible to write the following without the commented error: from typing import Any, Callable, Type, TypeVar from ...
X Description: This may be a known limitation of the type system, but it would be nice if it were possible to write the following without the commented error: from typing import Any, Callable, Type, TypeVar from ...
Opengraph URL: https://github.com/python/mypy/issues/8273
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bug - Type aliases in closure does not work","articleBody":"This may be a known limitation of the type system, but it would be nice if it were possible to write the following without the commented error:\r\n\r\n```python\r\nfrom typing import Any, Callable, Type, TypeVar\r\nfrom threading import Lock\r\n\r\nF = TypeVar(\"F\", bound=Callable[..., Any])\r\nDecorator = Callable[[F], F] # \u003c--- the problem type alias\r\n\r\ndef with_lock(lock: Lock) -> Decorator[F]:\r\n def decorator(function: F) -> F:\r\n def wrapper(*args, **kwargs) -> Any:\r\n with lock:\r\n return function(*args, **kwargs)\r\n return wrapper # type: ignore\r\n return decorator\r\n\r\nl = Lock()\r\n\r\nreveal_type(with_lock(l)) # note: Revealed type is 'def (\u003cnothing>) -> \u003cnothing>'\r\n\r\n@with_lock(l) # error: Argument 1 has incompatible type \"Callable[[Any], None]\"; expected \u003cnothing>\r\ndef use_resource(resource: Any) -> None:\r\n ...\r\n```\r\n\r\nIn order for this to work correctly I have to replace the type alias `Decorator` with the explicit `Callable[[F], F]`. This is trivial to change in this case, but for more complex types this would inhibit readability greatly.\r\n\r\n# Details:\r\n\r\nWhat version of MyPy: 0.761\r\nHave you tried on master: no\r\nAre there any flags engaged: no","author":{"url":"https://github.com/rmorshea","@type":"Person","name":"rmorshea"},"datePublished":"2020-01-11T00:13:38Z","url":"https://github.com/python/mypy/issues/8273"}
| 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:0a0bca70-1fc9-b728-b4a8-ee674cda25b7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BEEA:3C2A9A:13F5709:1A2581A:6B000855 |
| html-safe-nonce | 52684447e5429594b09ff0b3776b8118643089a4d659008b107f28fc0a4f4155 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRUVBOjNDMkE5QToxM0Y1NzA5OjFBMjU4MUE6NkIwMDA4NTUiLCJ2aXNpdG9yX2lkIjoiMzE1MzY4MTkyNDc0NTA3MDY3NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b352c20212594611015db9a0fc12414086b7910371bf058cfec7ac06ef8e59c7 |
| hovercard-subject-tag | issue:548348802 |
| 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/8273/issue_layout |
| twitter:image | https://opengraph.githubassets.com/46ebc73dc8779e1cf23fa33903c8d019a86db8a7c2dd2558cac3018d7c0b633a/python/mypy/issues/8273 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/46ebc73dc8779e1cf23fa33903c8d019a86db8a7c2dd2558cac3018d7c0b633a/python/mypy/issues/8273 |
| og:image:alt | This may be a known limitation of the type system, but it would be nice if it were possible to write the following without the commented error: from typing import Any, Callable, Type, TypeVar from ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rmorshea |
| 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