Title: mypy 0.730 no longer recognizes x**y literals to be ints · Issue #7621 · python/mypy · GitHub
Open Graph Title: mypy 0.730 no longer recognizes x**y literals to be ints · Issue #7621 · python/mypy
X Title: mypy 0.730 no longer recognizes x**y literals to be ints · Issue #7621 · python/mypy
Description: I noticed a regression when switching from 0.720 to 0.730. Here's the code: def f() -> int: size = 2 ** 20 reveal_type(size) return size Expected behavior With mypy 0.720 (no matter whether the new or the old semantic analyzer is used), ...
Open Graph Description: I noticed a regression when switching from 0.720 to 0.730. Here's the code: def f() -> int: size = 2 ** 20 reveal_type(size) return size Expected behavior With mypy 0.720 (no matter whether the new...
X Description: I noticed a regression when switching from 0.720 to 0.730. Here's the code: def f() -> int: size = 2 ** 20 reveal_type(size) return size Expected behavior With mypy 0.720 (no matter whether ...
Opengraph URL: https://github.com/python/mypy/issues/7621
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"mypy 0.730 no longer recognizes x**y literals to be ints","articleBody":"I noticed a regression when switching from 0.720 to 0.730. Here's the code:\r\n```py\r\ndef f() -> int:\r\n size = 2 ** 20\r\n reveal_type(size)\r\n return size\r\n```\r\n\r\n**Expected behavior**\r\n\r\nWith mypy 0.720 (no matter whether the new or the old semantic analyzer is used), I get:\r\n```\r\n$ mypy --strict f.py\r\nf.py:3: note: Revealed type is 'builtins.int'\r\n```\r\n**Actual behavior**\r\n\r\nWith mypy 0.730 (Python 3.6.8), I get:\r\n```\r\n$ mypy --strict f.py\r\nf.py:3: note: Revealed type is 'Any'\r\nf.py:4: error: Returning Any from function declared to return \"int\"\r\n```\r\n\r\n**Notes**\r\n\r\nThe behavior from 0.720 is what I'd expect.\r\n\r\nOne thing I noticed is that the typeshed indeed declares that `__pow__` for two `int`s returns `Any`. This makes sense because `2 ** -2` is a `float`. The only recent change which I can see in the typeshed though is the following: \r\n```diff\r\n--- a/stdlib/2and3/builtins.pyi\r\n+++ b/stdlib/2and3/builtins.pyi\r\n@@ -168,7 +168,7 @@ class int:\r\n def __rtruediv__(self, x: int) -> float: ...\r\n def __rmod__(self, x: int) -> int: ...\r\n def __rdivmod__(self, x: int) -> Tuple[int, int]: ...\r\n- def __pow__(self, x: int) -> Any: ... # Return type can be int or float, depending on x.\r\n+ def __pow__(self, __x: int, __modulo: Optional[int] = ...) -> Any: ... # Return type can be int or float, depending on x.\r\n def __rpow__(self, x: int) -> Any: ...\r\n def __and__(self, n: int) -> int: ...\r\n```\r\n(see: https://github.com/python/typeshed/commit/b2cd972b1760d850694772fe763e3027f131f223)\r\n\r\nThis means that the `Any` return type has always been there but `mypy` used to correctly recognize that `2 ** 20` is an `int`. It's difficult for me to tell whether the behavior in 0.730 is a regression compared to 0.720 or actually the desired behavior – it seems to me that `mypy` follows the typeshed more precisely here. However, maybe it's worth to handle literals like `2 ** 30` in a way that `mypy` knows that this is always `int`?","author":{"url":"https://github.com/marcinsulikowski","@type":"Person","name":"marcinsulikowski"},"datePublished":"2019-10-04T10:39:36Z","url":"https://github.com/python/mypy/issues/7621"}
| 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:4b08901b-f2b5-1417-1e19-75d966cd4d48 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B244:43251:173DB8B:1EEE4FD:6B002AB4 |
| html-safe-nonce | 599a1ac9f15bbceed8045f3af44a7579b2c5961e577276b679d5b941162efe4c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMjQ0OjQzMjUxOjE3M0RCOEI6MUVFRTRGRDo2QjAwMkFCNCIsInZpc2l0b3JfaWQiOiI3NDc4NjE2OTY0MjEwODk1NTQwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 54ce1e93fa34fbe06032a58c3fe87cff5fb974b2635f078c14bffaf188593f14 |
| hovercard-subject-tag | issue:502562626 |
| 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/7621/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dc1baaf2e75c9d958acd33ded84ae07c194a94ceb76ea922d3165f15a17cd988/python/mypy/issues/7621 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dc1baaf2e75c9d958acd33ded84ae07c194a94ceb76ea922d3165f15a17cd988/python/mypy/issues/7621 |
| og:image:alt | I noticed a regression when switching from 0.720 to 0.730. Here's the code: def f() -> int: size = 2 ** 20 reveal_type(size) return size Expected behavior With mypy 0.720 (no matter whether the new... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | marcinsulikowski |
| 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