Title: Doesn't correctly match overloads when calling method using conditional arguments · Issue #9264 · python/mypy · GitHub
Open Graph Title: Doesn't correctly match overloads when calling method using conditional arguments · Issue #9264 · python/mypy
X Title: Doesn't correctly match overloads when calling method using conditional arguments · Issue #9264 · python/mypy
Description: Are you reporting a bug, or opening a feature request? Bug report Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. We would appreciate if you try to simplify your case to a minimal rep...
Open Graph Description: Are you reporting a bug, or opening a feature request? Bug report Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. We would appreciate if you tr...
X Description: Are you reporting a bug, or opening a feature request? Bug report Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. We would appreciate if you tr...
Opengraph URL: https://github.com/python/mypy/issues/9264
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Doesn't correctly match overloads when calling method using conditional arguments","articleBody":"* Are you reporting a bug, or opening a feature request?\r\n\r\nBug report\r\n\r\n* Please insert below the code you are checking with mypy,\r\n or a mock-up repro if the source is private. We would appreciate\r\n if you try to simplify your case to a minimal repro.\r\n\r\n```python\r\nfrom typing import List, Optional\r\n\r\n\r\ndef example(data: Optional[List[int]] = None, size: int = 0) -> None:\r\n buffer = bytearray(data if data else size)\r\n print(buffer)\r\n\r\n\r\nexample(size=3)\r\nexample(data=[1, 2, 3])\r\n```\r\n\r\n* What is the actual behavior/output?\r\n```\r\nerror: No overload variant of \"bytearray\" matches argument type \"object\"\r\nnote: Possible overload variants:\r\nnote: def __init__(self, ints: Iterable[int]) -> bytearray\r\nnote: def __init__(self, length: int) -> bytearray\r\nnote: \u003c2 more non-matching overloads not shown>\r\n```\r\n\r\nI am forced to replace it with\r\n\r\n```python\r\nif data:\r\n buffer = bytearray(data)\r\nelse:\r\n buffer = bytearray(size)\r\n```\r\n\r\n* What is the behavior/output you expect?\r\n\r\nI would expect mypy to pass, as I believe the arguments passed to the bytearray constructor match the overloads.\r\n\r\n* What are the versions of mypy and Python you are using?\r\n Do you see the same issue after installing mypy from Git master?\r\n\r\nmypy 0.782\r\nmaster is the same\r\n\r\n* What are the mypy flags you are using? (For example --strict-optional)\r\n\r\n`mypy --strict`\r\n\r\n","author":{"url":"https://github.com/FFY00","@type":"Person","name":"FFY00"},"datePublished":"2020-08-04T22:10:54Z","url":"https://github.com/python/mypy/issues/9264"}
| 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:24fbf589-71cf-237a-cc37-104891365a85 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B050:59CDA:28FB30A:356D4FF:6B0007D3 |
| html-safe-nonce | 21780cef49ad0d2fc5ee0f641b23a114e171e13eab930ab277a3d0c9160afbfd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMDUwOjU5Q0RBOjI4RkIzMEE6MzU2RDRGRjo2QjAwMDdEMyIsInZpc2l0b3JfaWQiOiIyNTIwNDQyNjA1NzA4MjY3MDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8abe46da23406b4a2b9d28b82c1882276e7c4290d4060980f75e80e29c54914b |
| hovercard-subject-tag | issue:673115939 |
| 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/9264/issue_layout |
| twitter:image | https://opengraph.githubassets.com/105010cdbd7fc41eb1edab41063124c2479f8c80910f17632ccff39e3d6eb5a3/python/mypy/issues/9264 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/105010cdbd7fc41eb1edab41063124c2479f8c80910f17632ccff39e3d6eb5a3/python/mypy/issues/9264 |
| og:image:alt | Are you reporting a bug, or opening a feature request? Bug report Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. We would appreciate if you tr... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | FFY00 |
| 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