Title: Mixin class factory crash · Issue #12112 · python/mypy · GitHub
Open Graph Title: Mixin class factory crash · Issue #12112 · python/mypy
X Title: Mixin class factory crash · Issue #12112 · python/mypy
Description: Crash Report I run mypy against a file and it crashes. Traceback (pyle) danielsank@danielsank1:~/Desktop/test$ mypy --show-traceback code.py code.py:14: error: INTERNAL ERROR -- Please try using mypy master on Github: https://mypy.readth...
Open Graph Description: Crash Report I run mypy against a file and it crashes. Traceback (pyle) danielsank@danielsank1:~/Desktop/test$ mypy --show-traceback code.py code.py:14: error: INTERNAL ERROR -- Please try using my...
X Description: Crash Report I run mypy against a file and it crashes. Traceback (pyle) danielsank@danielsank1:~/Desktop/test$ mypy --show-traceback code.py code.py:14: error: INTERNAL ERROR -- Please try using my...
Opengraph URL: https://github.com/python/mypy/issues/12112
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mixin class factory crash","articleBody":"**Crash Report**\r\n\r\nI run mypy against a file and it crashes.\r\n\r\n**Traceback**\r\n\r\n```\r\n(pyle) danielsank@danielsank1:~/Desktop/test$ mypy --show-traceback code.py \r\ncode.py:14: 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: 0.940+dev.c0e49abcf27ff59e761f3ec06a24ee94e700464d\r\nTraceback (most recent call last):\r\n File \"/home/danielsank/.virtualenvs/pyle/bin/mypy\", line 8, in \u003cmodule>\r\n sys.exit(console_entry())\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/__main__.py\", line 12, in console_entry\r\n main(None, sys.stdout, sys.stderr)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/main.py\", line 96, in main\r\n res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/main.py\", line 173, in run_build\r\n res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/build.py\", line 180, in build\r\n result = _build(\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/build.py\", line 256, in _build\r\n graph = dispatch(sources, manager, stdout)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/build.py\", line 2715, in dispatch\r\n process_graph(graph, manager)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/build.py\", line 3046, in process_graph\r\n process_stale_scc(graph, scc, manager)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/build.py\", line 3138, in process_stale_scc\r\n mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal_main.py\", line 79, in semantic_analysis_for_scc\r\n process_functions(graph, scc, patches)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal_main.py\", line 233, in process_functions\r\n process_top_level_function(analyzer,\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal_main.py\", line 274, in process_top_level_function\r\n deferred, incomplete, progress = semantic_analyze_target(target, state, node, active_type,\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal_main.py\", line 326, in semantic_analyze_target\r\n analyzer.refresh_partial(refresh_node,\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal.py\", line 415, in refresh_partial\r\n self.accept(node)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal.py\", line 5171, in accept\r\n node.accept(self)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/nodes.py\", line 730, in accept\r\n return visitor.visit_func_def(self)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal.py\", line 628, in visit_func_def\r\n self.analyze_func_def(defn)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal.py\", line 671, in analyze_func_def\r\n self.analyze_function_body(defn)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal.py\", line 1001, in analyze_function_body\r\n defn.body.accept(self)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/nodes.py\", line 1077, in accept\r\n return visitor.visit_block(self)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal.py\", line 3566, in visit_block\r\n self.accept(s)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal.py\", line 5171, in accept\r\n node.accept(self)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/nodes.py\", line 1008, in accept\r\n return visitor.visit_class_def(self)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal.py\", line 1111, in visit_class_def\r\n self.analyze_class(defn)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal.py\", line 1189, in analyze_class\r\n self.analyze_class_body_common(defn)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal.py\", line 1197, in analyze_class_body_common\r\n defn.defs.accept(self)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/nodes.py\", line 1077, in accept\r\n return visitor.visit_block(self)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal.py\", line 3566, in visit_block\r\n self.accept(s)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal.py\", line 5171, in accept\r\n node.accept(self)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/nodes.py\", line 730, in accept\r\n return visitor.visit_func_def(self)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal.py\", line 628, in visit_func_def\r\n self.analyze_func_def(defn)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal.py\", line 660, in analyze_func_def\r\n self.defer(defn)\r\n File \"/home/danielsank/.virtualenvs/pyle/lib/python3.8/site-packages/mypy/semanal.py\", line 4871, in defer\r\n assert not self.final_iteration, 'Must not defer during final iteration'\r\nAssertionError: Must not defer during final iteration\r\ncode.py:14: : note: use --pdb to drop into pdb\r\n```\r\n\r\n**To Reproduce**\r\n\r\nThe offending code:\r\n\r\n```python\r\nfrom typing import cast, Dict, Generic, Type, TypeVar\r\n\r\ndef make_mixin(key: str):\r\n T = TypeVar('T', bound=\"Mixin\")\r\n # T represents an instance of a Mixin subclass.\r\n\r\n\r\n class Mixin(Generic[T]):\r\n\r\n KEY: str = key\r\n\r\n def to_str(self) -> str:\r\n return \"a string\"\r\n\r\n @classmethod\r\n def from_str(cls: Type[T], s: str) -> T:\r\n print(s)\r\n instance = cast(T, cls())\r\n return instance\r\n\r\n @classmethod\r\n def from_dict(cls: Type[T], d: Dict[str, str]) -> T:\r\n s = d[cls.KEY]\r\n return cls.from_str(s)\r\n```\r\n\r\nOn the other hand, this code **does not cause a crash**\r\n\r\n```python\r\nfrom typing import cast, Dict, Generic, Type, TypeVar\r\n\r\n\r\n\r\nT = TypeVar('T', bound=\"Mixin\")\r\n# T represents an instance of a Mixin subclass.\r\n\r\n\r\nclass Mixin(Generic[T]):\r\n\r\n KEY: str = 'foo'\r\n\r\n def to_str(self) -> str:\r\n return \"a string\"\r\n\r\n @classmethod\r\n def from_str(cls: Type[T], s: str) -> T:\r\n print(s)\r\n instance = cast(T, cls())\r\n return instance\r\n\r\n @classmethod\r\n def from_dict(cls: Type[T], d: Dict[str, str]) -> T:\r\n s = d[cls.KEY]\r\n return cls.from_str(s)\r\n```\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: `mypy 0.940+dev.c0e49abcf27ff59e761f3ec06a24ee94e700464d`\r\n- Mypy command-line flags: None\r\n- Mypy configuration options from `mypy.ini` (and other config files):\r\n- Python version used: 3.8.8\r\n- Operating system and version: Debian derivative\r\n","author":{"url":"https://github.com/DanielSank","@type":"Person","name":"DanielSank"},"datePublished":"2022-02-02T18:15:03Z","url":"https://github.com/python/mypy/issues/12112"}
| 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:7893160c-4727-311f-b338-337bcbb6c5ff |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AA5C:1BCD46:4304D7:5A0D0B:6B002CA8 |
| html-safe-nonce | 24d3d0172fcf46207e7e64ccc580ab302548670792ec7f240be7dafda5a6b18d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQTVDOjFCQ0Q0Njo0MzA0RDc6NUEwRDBCOjZCMDAyQ0E4IiwidmlzaXRvcl9pZCI6IjMyMTI0NjI1NTQwNzcwNTI1NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 158529c53b3ff6ac9002ff36c80fc24aa69c0a9406e32145c381042a874e9f3b |
| hovercard-subject-tag | issue:1122244687 |
| 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/12112/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6db20749fe57851f0e7f7752efd325ab7f2dee56e3ee41645cc62a0e7a0adc9d/python/mypy/issues/12112 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6db20749fe57851f0e7f7752efd325ab7f2dee56e3ee41645cc62a0e7a0adc9d/python/mypy/issues/12112 |
| og:image:alt | Crash Report I run mypy against a file and it crashes. Traceback (pyle) danielsank@danielsank1:~/Desktop/test$ mypy --show-traceback code.py code.py:14: error: INTERNAL ERROR -- Please try using my... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DanielSank |
| 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