Title: Incremental parsing crash with inline dynamic `enum.Enum` construction · Issue #16163 · python/mypy · GitHub
Open Graph Title: Incremental parsing crash with inline dynamic `enum.Enum` construction · Issue #16163 · python/mypy
X Title: Incremental parsing crash with inline dynamic `enum.Enum` construction · Issue #16163 · python/mypy
Description: Crash Report Given two files: # the_class.py import enum class TheClass: def __init__(self) -> None: names = ['foo'] # Note: the enum must be dynamic for the bug to reproduce. Replacing the # dict comprehension with a literal causes the ...
Open Graph Description: Crash Report Given two files: # the_class.py import enum class TheClass: def __init__(self) -> None: names = ['foo'] # Note: the enum must be dynamic for the bug to reproduce. Replacing the # dict ...
X Description: Crash Report Given two files: # the_class.py import enum class TheClass: def __init__(self) -> None: names = ['foo'] # Note: the enum must be dynamic for the bug to reproduce. Replacing ...
Opengraph URL: https://github.com/python/mypy/issues/16163
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incremental parsing crash with inline dynamic `enum.Enum` construction","articleBody":"**Crash Report**\r\n\r\nGiven two files:\r\n``` python\r\n# the_class.py\r\nimport enum\r\n\r\nclass TheClass:\r\n def __init__(self) -> None:\r\n names = ['foo']\r\n\r\n # Note: the enum must be dynamic for the bug to reproduce. Replacing the\r\n # dict comprehension with a literal causes the issue to go away.\r\n pyenum = enum.Enum('Blah', { # type: ignore[misc]\r\n x.upper(): x\r\n for x in names\r\n })\r\n\r\n # Note: the enum type must then be exposed somehow as a member of the\r\n # type. This doesn't need to be direct -- the original code was\r\n #\r\n # self.enum_type = strawberry.enum(pyenum)\r\n #\r\n # however the enum type seems to need to be somewhere public.\r\n self.enum_type = pyenum\r\n```\r\n``` python\r\n# usage.py\r\nfrom .the_class import TheClass\r\nprint(TheClass)\r\n```\r\narranged\r\n```\r\n$ tree\r\n.\r\n└── pkg\r\n ├── __init__.py # empty\r\n ├── the_class.py\r\n └── usage.py\r\n```\r\n\r\n**Traceback**\r\n\r\n```\r\nTraceback (most recent call last):\r\n File \"/home/peter/thread/styleme/venv/bin/mypy\", line 8, in \u003cmodule>\r\n sys.exit(console_entry())\r\n ^^^^^^^^^^^^^^^\r\n File \"/home/peter/thread/styleme/venv/lib/python3.11/site-packages/mypy/__main__.py\", line 15, in console_entry\r\n main()\r\n File \"mypy/main.py\", line 94, in main\r\n File \"mypy/main.py\", line 173, in run_build\r\n File \"mypy/build.py\", line 195, in build\r\n File \"mypy/build.py\", line 268, in _build\r\n File \"mypy/build.py\", line 2927, in dispatch\r\n File \"mypy/build.py\", line 3318, in process_graph\r\n File \"mypy/build.py\", line 3399, in process_fresh_modules\r\n File \"mypy/build.py\", line 2114, in fix_cross_refs\r\n File \"mypy/fixup.py\", line 52, in fixup_module\r\n File \"mypy/fixup.py\", line 135, in visit_symbol_table\r\n File \"mypy/fixup.py\", line 72, in visit_type_info\r\n File \"mypy/fixup.py\", line 137, in visit_symbol_table\r\n File \"mypy/nodes.py\", line 1038, in accept\r\n File \"mypy/fixup.py\", line 193, in visit_var\r\n File \"mypy/types.py\", line 1923, in accept\r\n File \"mypy/fixup.py\", line 247, in visit_callable_type\r\n File \"mypy/types.py\", line 1414, in accept\r\n File \"mypy/fixup.py\", line 212, in visit_instance\r\n File \"mypy/fixup.py\", line 349, in lookup_fully_qualified_typeinfo\r\n File \"mypy/lookup.py\", line 49, in lookup_fully_qualified\r\nAssertionError: Cannot find component 'pyenum' for 'pkg.the_class.TheClass.pyenum'\r\n```\r\n\r\n**To Reproduce**\r\n\r\nThe typecheck passes, however subsequent typechecks where the _usages_ of `TheClass` have changed will crash. Cases where mypy also re-parses `the_class.py` seem to work ok, presumably due to the types not being looked up in the cache.\r\n\r\n``` console\r\nrm -rf .mypy_cache/ && mypy . && echo \"# change to force re-check\" >> pkg/usage.py && mypy .\r\n```\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: `mypy 1.5.1 (compiled: yes)`\r\n- Mypy command-line flags: none\r\n- Mypy configuration options from `mypy.ini` (and other config files): none\r\n- Python version used: Python 3.11.5\r\n- Operating system and version: Ubuntu 22.04.3 LTS","author":{"url":"https://github.com/PeterJCLaw","@type":"Person","name":"PeterJCLaw"},"datePublished":"2023-09-22T10:29:46Z","url":"https://github.com/python/mypy/issues/16163"}
| 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:c870882b-96a5-e221-fc17-5a4a367aa3c5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8054:37308E:19604D5:20ABDE2:6AFFBAF8 |
| html-safe-nonce | b01f663169dc8f73add609d3b03522cdaf37fe9e93d7ac5e2c97308369aed354 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDU0OjM3MzA4RToxOTYwNEQ1OjIwQUJERTI6NkFGRkJBRjgiLCJ2aXNpdG9yX2lkIjoiNTM4MDg5MTMxMTE5ODk0Mzk5MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 852a98cc4011927ba6a2b553c7049a25c467f2e44429f1f2608c55a5f7169015 |
| hovercard-subject-tag | issue:1908644850 |
| 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/16163/issue_layout |
| twitter:image | https://opengraph.githubassets.com/aca7c612ba77fb1ee705ebbcd4bc3f417e00e7a5895f8c8067bf0dff38abdc24/python/mypy/issues/16163 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/aca7c612ba77fb1ee705ebbcd4bc3f417e00e7a5895f8c8067bf0dff38abdc24/python/mypy/issues/16163 |
| og:image:alt | Crash Report Given two files: # the_class.py import enum class TheClass: def __init__(self) -> None: names = ['foo'] # Note: the enum must be dynamic for the bug to reproduce. Replacing the # dict ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | PeterJCLaw |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7e461843db1c75e40d788c5cfd440d0e4ae1271cf19e06a798d0e7feb2d708f3 |
| 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 | d29a6a99861646939301302fab465f9f123b4773 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width