Title: Crash in version 1.11 lambda processing (regression since version 1.10) · Issue #17595 · python/mypy · GitHub
Open Graph Title: Crash in version 1.11 lambda processing (regression since version 1.10) · Issue #17595 · python/mypy
X Title: Crash in version 1.11 lambda processing (regression since version 1.10) · Issue #17595 · python/mypy
Description: Crash Report We maintain a large (1M+ LoC), proprietary Python code base, currently using mypy version 1.10. During an upgrade to version 1.11, I noticed some INTERNAL ERROR output so decided to investigate. Traceback bug.py:11: error: I...
Open Graph Description: Crash Report We maintain a large (1M+ LoC), proprietary Python code base, currently using mypy version 1.10. During an upgrade to version 1.11, I noticed some INTERNAL ERROR output so decided to in...
X Description: Crash Report We maintain a large (1M+ LoC), proprietary Python code base, currently using mypy version 1.10. During an upgrade to version 1.11, I noticed some INTERNAL ERROR output so decided to in...
Opengraph URL: https://github.com/python/mypy/issues/17595
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Crash in version 1.11 lambda processing (regression since version 1.10)","articleBody":"**Crash Report**\r\n\r\nWe maintain a large (1M+ LoC), proprietary Python code base, currently using mypy version 1.10. During an upgrade to version 1.11, I noticed some INTERNAL ERROR output so decided to investigate.\r\n\r\n**Traceback**\r\n\r\n```\r\nbug.py:11: error: INTERNAL ERROR -- Please try using mypy master on GitHub:\r\nhttps://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build\r\nPlease report a bug at https://github.com/python/mypy/issues\r\nversion: 1.11.0\r\nTraceback (most recent call last):\r\n File \"mypy/checkexpr.py\", line 5830, in accept\r\n File \"mypy/nodes.py\", line 2278, in accept\r\n File \"mypy/checkexpr.py\", line 5294, in visit_lambda_expr\r\n File \"/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/contextlib.py\", line 137, in __enter__\r\n return next(self.gen)\r\n ^^^^^^^^^^^^^^\r\n File \"mypy/binder.py\", line 436, in frame_context\r\nAssertionError:\r\n```\r\n\r\n**To Reproduce**\r\n\r\nSince I am unable to provide our full source code, I created the following small stand-alone example:\r\n\r\n```\r\ndef foo(x):\r\n pass\r\n\r\n\r\nclass Bar:\r\n def baz(self, x):\r\n pass\r\n\r\n\r\nclass Qux(Bar):\r\n @foo(lambda x: None)\r\n def baz(self, x) -> None:\r\n pass\r\n```\r\n\r\nThe crash seems to occur when a method decorator defined with a lambda overrides another method of the same name in a base class _and_ there's an annotation mismatch.\r\n\r\nThat is, for the above example, the crash can be avoided by adding a return value annotation to `baz()` in the base class:\r\n\r\n```\r\n class Bar:\r\n- def baz(self, x):\r\n+ def baz(self, x) -> None:\r\n pass\r\n```\r\n\r\n**Investigation**\r\n\r\nI narrowed the regression down to the following commit (the crash is avoided if I revert this change):\r\n\r\nhttps://github.com/python/mypy/commit/5059ffdd5df4702ae5b690a6dfd5f1a70c7964e1\r\n\r\nThe crash can also be avoided if I adjust the assertion at the crash site:\r\n\r\n```\r\n--- binder.py.bak\t2024-07-26 10:54:02\r\n+++ binder.py\t2024-07-26 10:54:07\r\n@@ -433,7 +433,7 @@\r\n whether any types changed in the newly-topmost frame as a result\r\n of popping this frame.\r\n \"\"\"\r\n- assert len(self.frames) > 1\r\n+ assert len(self.frames) > 0\r\n\r\n if break_frame:\r\n self.break_frames.append(len(self.frames) - break_frame)\r\n```\r\n\r\n`pytest -q mypy` passes after this change, and a full run of mypy 1.11 on our large code base also succeeds without any tracebacks or obvious ill-effects, but I'm otherwise not familiar enough with the innards of mypy to have confidence in its correctness (hence I felt more comfortable providing the FYI here instead of submitting a PR).\r\n\r\n**Your Environment**\r\n\r\n\u003c!-- Include as many relevant details about the environment you experienced the bug in -->\r\n\r\n- Mypy version used: 1.11\r\n- Mypy command-line flags: None (defaults)\r\n- Mypy configuration options from `mypy.ini` (and other config files): Reproduced with defaults\r\n- Python version used: 3.11.9\r\n- Operating system and version: macOS Sonoma 14.5\r\n\r\n","author":{"url":"https://github.com/acamatcisco","@type":"Person","name":"acamatcisco"},"datePublished":"2024-07-26T14:25:39Z","url":"https://github.com/python/mypy/issues/17595"}
| 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:6ee62afd-0982-4a0e-d28d-e6f2f7921a67 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CEF0:26206F:2C636BA:3A695AE:6B0018F3 |
| html-safe-nonce | bf23c777fcafb3eab1b0beeaf101fa7b7b4144fa3102116493aafd6800cd9a2a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRUYwOjI2MjA2RjoyQzYzNkJBOjNBNjk1QUU6NkIwMDE4RjMiLCJ2aXNpdG9yX2lkIjoiNzk5MjM5MzA0MjQ5MTM0OTIzNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 30c6a5c4941fe75dcacd01089b80adfc70352b1dfb01bda8d2d197f8537c82a6 |
| hovercard-subject-tag | issue:2432359271 |
| 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/17595/issue_layout |
| twitter:image | https://opengraph.githubassets.com/aba214bd587852cfecca1685fd727c2083f850c97f0ae48f6b698e1948f2baf9/python/mypy/issues/17595 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/aba214bd587852cfecca1685fd727c2083f850c97f0ae48f6b698e1948f2baf9/python/mypy/issues/17595 |
| og:image:alt | Crash Report We maintain a large (1M+ LoC), proprietary Python code base, currently using mypy version 1.10. During an upgrade to version 1.11, I noticed some INTERNAL ERROR output so decided to in... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | acamatcisco |
| hostname | github.com |
| expected-hostname | github.com |
| None | a2dd2291b1b13cc9c06f27ec92fa3dbaf34116fc24c9347b8539db61884c59f4 |
| 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 | 70121d4e855ee0bb7b75cf15d061d91f8863c0f8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width