Title: Any inferred when overloaded function called with None argument · Issue #3256 · python/mypy · GitHub
Open Graph Title: Any inferred when overloaded function called with None argument · Issue #3256 · python/mypy
X Title: Any inferred when overloaded function called with None argument · Issue #3256 · python/mypy
Description: Mypy infers Any when calling a precisely typed overloaded function with a None argument (without strict optional checking). This is undesirable, since an Any is silently generated: from typing import overload @overload def f(x: int) -> i...
Open Graph Description: Mypy infers Any when calling a precisely typed overloaded function with a None argument (without strict optional checking). This is undesirable, since an Any is silently generated: from typing impo...
X Description: Mypy infers Any when calling a precisely typed overloaded function with a None argument (without strict optional checking). This is undesirable, since an Any is silently generated: from typing impo...
Opengraph URL: https://github.com/python/mypy/issues/3256
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Any inferred when overloaded function called with None argument","articleBody":"Mypy infers `Any` when calling a precisely typed overloaded function with a `None` argument (without strict optional checking). This is undesirable, since an `Any` is silently generated:\r\n\r\n```py\r\nfrom typing import overload\r\n\r\n@overload\r\ndef f(x: int) -> int:\r\n pass\r\n@overload\r\ndef f(x: str) -> str:\r\n pass\r\n\r\ndef f(x): pass\r\n\r\nreveal_type(f(None)) # Any\r\n```\r\n\r\nNot sure what's the right thing to do here -- we can either generate a message that says that the overload target is ambiguous, or infer `Union[int, str]` as the return type. \r\n\r\nNote that explicitly including a `None` overload variant does not work as a workaround:\r\n\r\n```py\r\nfrom typing import overload\r\n\r\n@overload\r\ndef f(x: None) -> int: # Overloaded function signatures 1 and 3 overlap with \r\n # incompatible return types\r\n pass\r\n@overload\r\ndef f(x: int) -> int:\r\n pass\r\n@overload\r\ndef f(x: str) -> str:\r\n pass\r\n\r\ndef f(x): pass\r\n```\r\n\r\nThis is related to https://github.com/python/mypy/issues/1322.","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2017-04-26T16:02:15Z","url":"https://github.com/python/mypy/issues/3256"}
| 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:88df95b6-9aa3-c0c9-48ad-46e66036044d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8662:3A13A0:1C022C2:25C4C54:6B0005F3 |
| html-safe-nonce | a5831cb56dcc2bd39b34e8982576b807ffcbee8a57062882eca8db042393d718 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjYyOjNBMTNBMDoxQzAyMkMyOjI1QzRDNTQ6NkIwMDA1RjMiLCJ2aXNpdG9yX2lkIjoiNDE4MTg1ODc2NzExOTMyMDU2MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d5ba5bd8ce36a2b4f7b07cc7bcd9e59d09ee2d5d42fd0213e3d5544e28b7cd85 |
| hovercard-subject-tag | issue:224519542 |
| 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/3256/issue_layout |
| twitter:image | https://opengraph.githubassets.com/884080295ade354b997a554d5dc2a4291e9300a64d620341c788ac8a884c39bc/python/mypy/issues/3256 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/884080295ade354b997a554d5dc2a4291e9300a64d620341c788ac8a884c39bc/python/mypy/issues/3256 |
| og:image:alt | Mypy infers Any when calling a precisely typed overloaded function with a None argument (without strict optional checking). This is undesirable, since an Any is silently generated: from typing impo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JukkaL |
| 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