Title: Internal error on dataclasses with properties · Issue #6493 · python/mypy · GitHub
Open Graph Title: Internal error on dataclasses with properties · Issue #6493 · python/mypy
X Title: Internal error on dataclasses with properties · Issue #6493 · python/mypy
Description: On CPython 3.7.2 [GCC 7.3.0] on linux, with mypy 0.670 When attempting to follow the guidelines described in this article As illustrated here: from dataclasses import dataclass from typing import Optional @dataclass(init=False) class C: ...
Open Graph Description: On CPython 3.7.2 [GCC 7.3.0] on linux, with mypy 0.670 When attempting to follow the guidelines described in this article As illustrated here: from dataclasses import dataclass from typing import O...
X Description: On CPython 3.7.2 [GCC 7.3.0] on linux, with mypy 0.670 When attempting to follow the guidelines described in this article As illustrated here: from dataclasses import dataclass from typing import O...
Opengraph URL: https://github.com/python/mypy/issues/6493
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Internal error on dataclasses with properties","articleBody":"On CPython 3.7.2 [GCC 7.3.0] on linux, with mypy 0.670\r\n\r\nWhen attempting to follow the guidelines described in [this article](https://blog.florimondmanca.com/reconciling-dataclasses-and-properties-in-python)\r\n\r\nAs illustrated here:\r\n\r\n```\r\nfrom dataclasses import dataclass\r\nfrom typing import Optional\r\n\r\n\r\n@dataclass(init=False)\r\nclass C:\r\n a: Optional[int]\r\n\r\n def __init__(self, a: Optional[int] = None) -> None:\r\n self._a = None\r\n self.a = a\r\n\r\n @property\r\n def a(self) -> Optional[int]:\r\n return self._a\r\n\r\n @a.setter\r\n def a(self, value: Optional[int]) -> Optional[int]:\r\n self._a = value\r\n return self._a\r\n```\r\n\r\nMypy (without options) raises an `INTERNAL ERROR` with the following:\r\n\r\n```\r\nTraceback (most recent call last):\r\n File \".../bin/mypy\", line 10, in \u003cmodule>\r\n sys.exit(console_entry())\r\n File \".../lib/python3.7/site-packages/mypy/__main__.py\", line 7, in console_entry\r\n main(None)\r\n File \".../lib/python3.7/site-packages/mypy/main.py\", line 91, in main\r\n res = build.build(sources, options, None, flush_errors, fscache)\r\n File \".../lib/python3.7/site-packages/mypy/build.py\", line 162, in build\r\n result = _build(sources, options, alt_lib_path, flush_errors, fscache)\r\n File \".../lib/python3.7/site-packages/mypy/build.py\", line 217, in _build\r\n graph = dispatch(sources, manager)\r\n File \".../lib/python3.7/site-packages/mypy/build.py\", line 2360, in dispatch\r\n process_graph(graph, manager)\r\n File \".../lib/python3.7/site-packages/mypy/build.py\", line 2660, in process_graph\r\n process_stale_scc(graph, scc, manager)\r\n File \".../lib/python3.7/site-packages/mypy/build.py\", line 2761, in process_stale_scc\r\n graph[id].semantic_analysis()\r\n File \".../lib/python3.7/site-packages/mypy/build.py\", line 1896, in semantic_analysis\r\n self.manager.semantic_analyzer.visit_file(self.tree, self.xpath, self.options, patches)\r\n File \".../lib/python3.7/site-packages/mypy/semanal.py\", line 306, in visit_file\r\n self.accept(d)\r\n File \".../lib/python3.7/site-packages/mypy/semanal.py\", line 3787, in accept\r\n node.accept(self)\r\n File \".../lib/python3.7/site-packages/mypy/nodes.py\", line 846, in accept\r\n return visitor.visit_class_def(self)\r\n File \".../lib/python3.7/site-packages/mypy/semanal.py\", line 804, in visit_class_def\r\n self.analyze_class(defn)\r\n File \".../lib/python3.7/site-packages/mypy/semanal.py\", line 822, in analyze_class\r\n self.analyze_class_body_common(defn)\r\n File \".../lib/python3.7/site-packages/mypy/semanal.py\", line 830, in analyze_class_body_common\r\n self.apply_class_plugin_hooks(defn)\r\n File \".../lib/python3.7/site-packages/mypy/semanal.py\", line 892, in apply_class_plugin_hooks\r\n hook(ClassDefContext(defn, decorator, self))\r\n File \".../lib/python3.7/site-packages/mypy/plugins/dataclasses.py\", line 312, in dataclass_class_maker_callback\r\n transformer.transform()\r\n File \".../lib/python3.7/site-packages/mypy/plugins/dataclasses.py\", line 79, in transform\r\n attributes = self.collect_attributes()\r\n File \".../lib/python3.7/site-packages/mypy/plugins/dataclasses.py\", line 189, in collect_attributes\r\n assert isinstance(node, Var)\r\nAssertionError:\r\n```\r\nAny suggestions about workarounds or better implementations of the initial premise would be much appreciated!","author":{"url":"https://github.com/ckanesan","@type":"Person","name":"ckanesan"},"datePublished":"2019-02-28T09:22:13Z","url":"https://github.com/python/mypy/issues/6493"}
| 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:63d40bb2-1491-746b-5275-0f1728cf5520 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CD94:2F2EB9:35000CE:468E7FD:6B004758 |
| html-safe-nonce | 6f6a4df142c92a98ec8da4a90d73159c42f8f44031815a8357db4a1d2b30f49a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRDk0OjJGMkVCOTozNTAwMENFOjQ2OEU3RkQ6NkIwMDQ3NTgiLCJ2aXNpdG9yX2lkIjoiNDE5MjI4NTk1MTI4MTYxMjYzMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d53ffc95228274d7e8312df17831f838d480576b4c2634831ecf7be7e6bc147e |
| hovercard-subject-tag | issue:415522608 |
| 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/6493/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9d5a66b7a0b3a5f8507cdae4fb9ecae0b2b6f8cfef7900d76c37634999f53eee/python/mypy/issues/6493 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9d5a66b7a0b3a5f8507cdae4fb9ecae0b2b6f8cfef7900d76c37634999f53eee/python/mypy/issues/6493 |
| og:image:alt | On CPython 3.7.2 [GCC 7.3.0] on linux, with mypy 0.670 When attempting to follow the guidelines described in this article As illustrated here: from dataclasses import dataclass from typing import O... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ckanesan |
| 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