Title: Crash when using total_ordering and a Generic class · Issue #11728 · python/mypy · GitHub
Open Graph Title: Crash when using total_ordering and a Generic class · Issue #11728 · python/mypy
X Title: Crash when using total_ordering and a Generic class · Issue #11728 · python/mypy
Description: Crash Report When using a test snippet that uses functools.total_ordering and a Generic class whose TypeVar is bound by some other class, there is an internal crash in mypy. The reproduction cases are below the traceback. This may be rel...
Open Graph Description: Crash Report When using a test snippet that uses functools.total_ordering and a Generic class whose TypeVar is bound by some other class, there is an internal crash in mypy. The reproduction cases ...
X Description: Crash Report When using a test snippet that uses functools.total_ordering and a Generic class whose TypeVar is bound by some other class, there is an internal crash in mypy. The reproduction cases ...
Opengraph URL: https://github.com/python/mypy/issues/11728
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Crash when using total_ordering and a Generic class","articleBody":"**Crash Report**\r\n\r\nWhen using a test snippet that uses `functools.total_ordering` and a `Generic` class whose `TypeVar` is bound by some other class, there is an internal crash in mypy. The reproduction cases are below the traceback.\r\n\r\nThis may be related to #8539, but in this case, there is no abstract class involved\r\n\r\n**Traceback**\r\n\r\n```\r\n$ mypy --show-traceback test_mypy.py\r\ntest_mypy.py:9: 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.920+dev.01a2d98bc480ea9e1575f2adab47c0cfbca1c8d0\r\nTraceback (most recent call last):\r\n File \"/usr/scratch/stum/mypy-repro/bin/mypy\", line 8, in \u003cmodule>\r\n sys.exit(console_entry())\r\n File \"/usr/scratch/stum/mypy-repro/lib/python3.8/site-packages/mypy/__main__.py\", line 12, in console_entry\r\n main(None, sys.stdout, sys.stderr)\r\n File \"/usr/scratch/stum/mypy-repro/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 \"/usr/scratch/stum/mypy-repro/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 \"/usr/scratch/stum/mypy-repro/lib/python3.8/site-packages/mypy/build.py\", line 180, in build\r\n result = _build(\r\n File \"/usr/scratch/stum/mypy-repro/lib/python3.8/site-packages/mypy/build.py\", line 256, in _build\r\n graph = dispatch(sources, manager, stdout)\r\n File \"/usr/scratch/stum/mypy-repro/lib/python3.8/site-packages/mypy/build.py\", line 2720, in dispatch\r\n process_graph(graph, manager)\r\n File \"/usr/scratch/stum/mypy-repro/lib/python3.8/site-packages/mypy/build.py\", line 3051, in process_graph\r\n process_stale_scc(graph, scc, manager)\r\n File \"/usr/scratch/stum/mypy-repro/lib/python3.8/site-packages/mypy/build.py\", line 3143, in process_stale_scc\r\n mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)\r\n File \"/usr/scratch/stum/mypy-repro/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 \"/usr/scratch/stum/mypy-repro/lib/python3.8/site-packages/mypy/semanal_main.py\", line 233, in process_functions\r\n process_top_level_function(analyzer,\r\n File \"/usr/scratch/stum/mypy-repro/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 \"/usr/scratch/stum/mypy-repro/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 \"/usr/scratch/stum/mypy-repro/lib/python3.8/site-packages/mypy/semanal.py\", line 408, in refresh_partial\r\n self.accept(node)\r\n File \"/usr/scratch/stum/mypy-repro/lib/python3.8/site-packages/mypy/semanal.py\", line 5092, in accept\r\n node.accept(self)\r\n File \"/usr/scratch/stum/mypy-repro/lib/python3.8/site-packages/mypy/nodes.py\", line 727, in accept\r\n return visitor.visit_func_def(self)\r\n File \"/usr/scratch/stum/mypy-repro/lib/python3.8/site-packages/mypy/semanal.py\", line 621, in visit_func_def\r\n self.analyze_func_def(defn)\r\n File \"/usr/scratch/stum/mypy-repro/lib/python3.8/site-packages/mypy/semanal.py\", line 653, in analyze_func_def\r\n self.defer(defn)\r\n File \"/usr/scratch/stum/mypy-repro/lib/python3.8/site-packages/mypy/semanal.py\", line 4776, in defer\r\n assert not self.final_iteration, 'Must not defer during final iteration'\r\nAssertionError: Must not defer during final iteration\r\ntest_mypy.py:9: : note: use --pdb to drop into pdb\r\n```\r\n\r\n**To Reproduce**\r\n\r\nHere is basically the smallest example I could come up with:\r\n```python\r\nfrom typing import Generic, Any, TypeVar\r\nimport functools\r\n\r\nT = TypeVar(\"T\", bound=\"C\")\r\n\r\n@functools.total_ordering\r\nclass D(Generic[T]):\r\n def __lt__(self, other: Any) -> bool:\r\n ...\r\n\r\n\r\nclass C:\r\n pass\r\n```\r\n\r\nA workaround (to suppress the crash) is to use a `total_ordering` that is essentially a no-op, that skips the mypy total_ordering plugin. Some ways that I've done this are:\r\n```python\r\nimport functools\r\ntotal_ordering = functools.total_ordering\r\n\r\n@total_ordering\r\nclass D(Generic[T]): ...\r\n```\r\nor\r\n```python\r\nif TYPE_CHECKING:\r\n _T = TypeVar(\"_T\")\r\n def total_ordering(cls: Type[_T]) -> Type[_T]:\r\n return cls\r\nelse:\r\n from functools import total_ordering\r\n\r\n@total_ordering\r\nclass D(Generic[T]): ...\r\n```\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 01a2d98bc480ea9e1575f2adab47c0cfbca1c8d0\r\n- Mypy command-line flags: None\r\n- Mypy configuration options from `mypy.ini` (and other config files): No mypy.ini\r\n- Python version used: Python 3.8\r\n- Operating system and version: Debian 10","author":{"url":"https://github.com/tjstum","@type":"Person","name":"tjstum"},"datePublished":"2021-12-13T22:46:36Z","url":"https://github.com/python/mypy/issues/11728"}
| 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:498c8c4e-5bf0-2ce3-9c20-56edd43be011 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C0F4:30263F:22E1DDD:2F7A782:6B002CB5 |
| html-safe-nonce | c0ffe91fbbcfe9069399d2c84bf37360554b171b8e94114a938aeae8b3b937b6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMEY0OjMwMjYzRjoyMkUxREREOjJGN0E3ODI6NkIwMDJDQjUiLCJ2aXNpdG9yX2lkIjoiNjEwOTIzNTMwOTgxODQyNDUwMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b84e1f0deb4d9a701a8968dd1d02d6dabfdbf30a7b41c3eca31b723dd545a143 |
| hovercard-subject-tag | issue:1079109100 |
| 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/11728/issue_layout |
| twitter:image | https://opengraph.githubassets.com/68fed4d824cc9241ad1cce954c34fcf640b55b5c9c1a51a90c5a63bb2038be8e/python/mypy/issues/11728 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/68fed4d824cc9241ad1cce954c34fcf640b55b5c9c1a51a90c5a63bb2038be8e/python/mypy/issues/11728 |
| og:image:alt | Crash Report When using a test snippet that uses functools.total_ordering and a Generic class whose TypeVar is bound by some other class, there is an internal crash in mypy. The reproduction cases ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tjstum |
| 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