Title: Internal error on processing NamedTuple with method and recursive field · Issue #8695 · python/mypy · GitHub
Open Graph Title: Internal error on processing NamedTuple with method and recursive field · Issue #8695 · python/mypy
X Title: Internal error on processing NamedTuple with method and recursive field · Issue #8695 · python/mypy
Description: Checking following code with mypy results in INTERNAL ERROR: maximum semantic analysis iteration count reached along with Deferral trace cycling with lines 7, 7 and -1 from typing import NamedTuple class First(NamedTuple): def method(sel...
Open Graph Description: Checking following code with mypy results in INTERNAL ERROR: maximum semantic analysis iteration count reached along with Deferral trace cycling with lines 7, 7 and -1 from typing import NamedTuple...
X Description: Checking following code with mypy results in INTERNAL ERROR: maximum semantic analysis iteration count reached along with Deferral trace cycling with lines 7, 7 and -1 from typing import NamedTuple...
Opengraph URL: https://github.com/python/mypy/issues/8695
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Internal error on processing NamedTuple with method and recursive field","articleBody":"Checking following code with mypy results in `INTERNAL ERROR: maximum semantic analysis iteration count reached` along with `Deferral trace` cycling with lines 7, 7 and -1\r\n\r\n```python\r\nfrom typing import NamedTuple\r\n\r\nclass First(NamedTuple):\r\n def method(self):\r\n pass\r\n\r\nclass Second(NamedTuple):\r\n recursive: 'Second'\r\n```\r\n\r\nAs far as I've debugged mypy code I think it is caused by [`analyze_class_body_common` being called under `save_namedtuple_body` contextmanager](https://github.com/python/mypy/blob/69eb6fe8a8d7d091e2902b490ad6b43e6fed3d41/mypy/semanal.py#L1106) which [sets empty SymbolTable for class](https://github.com/python/mypy/blob/69eb6fe8a8d7d091e2902b490ad6b43e6fed3d41/mypy/semanal_namedtuple.py#L489).\r\nThen `analyze_class_body_common` processes methods defined in class body, method definition is processed through [`SemanticAnalyzer.visit_func_def` which calls `add_function_to_symbol_table`](https://github.com/python/mypy/blob/69eb6fe8a8d7d091e2902b490ad6b43e6fed3d41/mypy/semanal.py#L524).\r\nUltimately [`add_symbol_table_node` upon not seeing that method was already handled (because we've cleared SymbolTable), sets `SemanticAnalyzer#progress = True`](https://github.com/python/mypy/blob/69eb6fe8a8d7d091e2902b490ad6b43e6fed3d41/mypy/semanal.py#L4282) on every analysis iteration, [preventing `process_top_levels` from setting `final_iteration` which breaks analysis cycle](https://github.com/python/mypy/blob/69eb6fe8a8d7d091e2902b490ad6b43e6fed3d41/mypy/semanal_main.py#L190)","author":{"url":"https://github.com/michalbednarski","@type":"Person","name":"michalbednarski"},"datePublished":"2020-04-18T14:40:24Z","url":"https://github.com/python/mypy/issues/8695"}
| 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:e9a3bfb7-4468-f996-55a6-5617ac3ffb0a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E366:D064:23B894C:308A449:6B002CC7 |
| html-safe-nonce | 19c9b46bae339a1ed8cfa03e60562f1b3647ec24e07366e092c35aef84f13e26 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMzY2OkQwNjQ6MjNCODk0QzozMDhBNDQ5OjZCMDAyQ0M3IiwidmlzaXRvcl9pZCI6IjMxMTMzOTA2MDAzMTgxMDI3MjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 51f1b286bcde181a53799be96cd875a5b5bfff96b04fb7e4220afa5a7056bfd6 |
| hovercard-subject-tag | issue:602475304 |
| 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/8695/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b9349aa5749e8c874205a27d48fdc8a3505ba21a22a8a584a90fbc3b6effde42/python/mypy/issues/8695 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b9349aa5749e8c874205a27d48fdc8a3505ba21a22a8a584a90fbc3b6effde42/python/mypy/issues/8695 |
| og:image:alt | Checking following code with mypy results in INTERNAL ERROR: maximum semantic analysis iteration count reached along with Deferral trace cycling with lines 7, 7 and -1 from typing import NamedTuple... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | michalbednarski |
| 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