Title: Running mypy with --disallow-untyped-decorators reports an error for overloaded decorators · Issue #4191 · python/mypy · GitHub
Open Graph Title: Running mypy with --disallow-untyped-decorators reports an error for overloaded decorators · Issue #4191 · python/mypy
X Title: Running mypy with --disallow-untyped-decorators reports an error for overloaded decorators · Issue #4191 · python/mypy
Description: Running mypy --disallow-untyped-decorators with a decorator that defines overloads always seems to report: Untyped decorator makes function "xxx" untyped Even though reveal_type(...) calls on the decorated functions seem to indicate type...
Open Graph Description: Running mypy --disallow-untyped-decorators with a decorator that defines overloads always seems to report: Untyped decorator makes function "xxx" untyped Even though reveal_type(...) calls on the d...
X Description: Running mypy --disallow-untyped-decorators with a decorator that defines overloads always seems to report: Untyped decorator makes function "xxx" untyped Even though reveal_type(...) call...
Opengraph URL: https://github.com/python/mypy/issues/4191
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Running mypy with --disallow-untyped-decorators reports an error for overloaded decorators","articleBody":"Running mypy --disallow-untyped-decorators with a decorator that defines overloads always seems to report:\r\n\r\nUntyped decorator makes function \"xxx\" untyped\r\n\r\nEven though reveal_type(...) calls on the decorated functions seem to indicate type information.\r\n\r\nConsider the following code. \r\n\r\nRunning mypy --disallow-untyped-decorators here yields the following (mypy 0.540):\r\n\r\n```\r\ndec_issue.py:19: error: Overloaded function signatures 1 and 2 overlap with incompatible return types\r\ndec_issue.py:35: error: Untyped decorator makes function \"default\" untyped\r\ndec_issue.py:41: error: Revealed type is 'def (*Any, **Any) -> builtins.int*'\r\n```\r\n\r\nThe first error seems to be covered by other bug reports here (though, for all I know it may be related).\r\n\r\nHowever, the second error seems to be contradicted by the type_reveal, which indicates at least the return type of the decorated \"default\" function is being picked up. \r\n\r\nI may be missing something, but at very least, it seems like a more descriptive error may be warranted? \r\n\r\n```python\r\nfrom typing import *\r\n\r\nR = TypeVar(\"R\")\r\n\r\n\r\ndef _make_decorator(arg: str) -> Callable[[Callable[..., R]], Callable[..., R]]:\r\n def dec_(fn: Callable[..., R]) -> Callable[..., R]:\r\n def wrapped(*args: Tuple[Any, ...],\r\n **kwargs: Dict[str, Any]) -> R:\r\n print(f\"Prefix {arg}!\")\r\n return fn(*args, **kwargs)\r\n\r\n return wrapped\r\n\r\n return dec_\r\n\r\n\r\n@overload\r\ndef dec(x: Callable[..., R]) -> Callable[..., R]: ...\r\n\r\n\r\n@overload\r\ndef dec(x: str) -> Callable[[Callable[..., R]], Callable[..., R]]: ...\r\n\r\n\r\ndef dec(x: Any) -> Any:\r\n if isinstance(x, str):\r\n return _make_decorator(x)\r\n elif callable(x):\r\n return _make_decorator(\"default\")(x)\r\n else:\r\n raise Exception(\"unhandled\")\r\n\r\n\r\n@dec\r\ndef default(name: str) -> int:\r\n print(f\"Hello, {name}!\")\r\n return 0\r\n\r\n\r\nreveal_type(default)\r\n\r\n\r\n@dec(\"arg\")\r\ndef arg(name: str) -> int:\r\n print(f\"Hello, {name}!\")\r\n return 0\r\n\r\n\r\nif __name__ == \"__main__\":\r\n default(\"Bob\")\r\n arg(\"Bob\")\r\n\r\n```\r\n\r\n\r\n\r\n","author":{"url":"https://github.com/joshstaiger","@type":"Person","name":"joshstaiger"},"datePublished":"2017-11-01T17:49:57Z","url":"https://github.com/python/mypy/issues/4191"}
| 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:48c0398e-f0f6-2e0f-6701-a8312d2641eb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 93F0:B5253:195B116:219114A:6B002C0B |
| html-safe-nonce | 1dfb292c193447067f89abe243b5a2d845988a1fa174c6976730ae5153e7140e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5M0YwOkI1MjUzOjE5NUIxMTY6MjE5MTE0QTo2QjAwMkMwQiIsInZpc2l0b3JfaWQiOiI0MTYwODIzMTAzOTMwMjQ4MjAzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d702ad2216cbcf55788b71657d71a9c28a398b91af9326a375b07918a4d0eba8 |
| hovercard-subject-tag | issue:270393205 |
| 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/4191/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ea9f28741da90d22bcefcc0368b08bd6704c1d4d3a9b8a4f669fec5bc94bf482/python/mypy/issues/4191 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ea9f28741da90d22bcefcc0368b08bd6704c1d4d3a9b8a4f669fec5bc94bf482/python/mypy/issues/4191 |
| og:image:alt | Running mypy --disallow-untyped-decorators with a decorator that defines overloads always seems to report: Untyped decorator makes function "xxx" untyped Even though reveal_type(...) calls on the d... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | joshstaiger |
| 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