Title: Internal error checking xarray with `--check-untyped-defs` · Issue #11007 · python/mypy · GitHub
Open Graph Title: Internal error checking xarray with `--check-untyped-defs` · Issue #11007 · python/mypy
X Title: Internal error checking xarray with `--check-untyped-defs` · Issue #11007 · python/mypy
Description: Crash Report Not sure whether this is a mypy issue, or an xarray issue... but I'm getting RuntimeError: TypeGuard should not appear here when running mypy on a file that imports xarray when using the --check-untyped-defs flag. Minimal en...
Open Graph Description: Crash Report Not sure whether this is a mypy issue, or an xarray issue... but I'm getting RuntimeError: TypeGuard should not appear here when running mypy on a file that imports xarray when using t...
X Description: Crash Report Not sure whether this is a mypy issue, or an xarray issue... but I'm getting RuntimeError: TypeGuard should not appear here when running mypy on a file that imports xarray when usi...
Opengraph URL: https://github.com/python/mypy/issues/11007
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Internal error checking xarray with `--check-untyped-defs`","articleBody":"**Crash Report**\r\n\r\nNot sure whether this is a mypy issue, or an xarray issue... but I'm getting `RuntimeError: TypeGuard should not appear here` when running mypy on a file that imports [xarray](https://github.com/pydata/xarray) when using the `--check-untyped-defs` flag. Minimal env on mypy master:\r\n\r\n**To Reproduce**\r\n\r\n```\r\nconda create -n test -c conda-forge python\r\nconda activate test\r\npip install xarray\r\npip install git+https://github.com/python/mypy.git\r\necho \"import xarray\" > m.py\r\nmypy --check-untyped-defs --show-traceback m.py\r\n``` \r\n\r\n**Traceback**\r\n\r\n```\r\n❯ mypy --check-untyped-defs --show-traceback m.py\r\n/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/xarray/core/common.py:1659: 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.7576f659d42ee271c78e69d7481b9d49517a49f6\r\nTraceback (most recent call last):\r\n File \"/Users/talley/miniconda3/envs/test/bin/mypy\", line 8, in \u003cmodule>\r\n sys.exit(console_entry())\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/__main__.py\", line 11, in console_entry\r\n main(None, sys.stdout, sys.stderr)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/main.py\", line 87, in main\r\n res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/main.py\", line 165, in run_build\r\n res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/build.py\", line 179, in build\r\n result = _build(\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/build.py\", line 254, in _build\r\n graph = dispatch(sources, manager, stdout)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/build.py\", line 2707, in dispatch\r\n process_graph(graph, manager)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/build.py\", line 3031, in process_graph\r\n process_stale_scc(graph, scc, manager)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/build.py\", line 3129, in process_stale_scc\r\n graph[id].type_check_first_pass()\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/build.py\", line 2175, in type_check_first_pass\r\n self.type_checker().check_first_pass()\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checker.py\", line 295, in check_first_pass\r\n self.accept(d)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checker.py\", line 402, in accept\r\n stmt.accept(self)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/nodes.py\", line 530, in accept\r\n return visitor.visit_overloaded_func_def(self)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checker.py\", line 435, in visit_overloaded_func_def\r\n self._visit_overloaded_func_def(defn)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checker.py\", line 457, in _visit_overloaded_func_def\r\n defn.impl.accept(self)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/nodes.py\", line 696, in accept\r\n return visitor.visit_func_def(self)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checker.py\", line 734, in visit_func_def\r\n self._visit_func_def(defn)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checker.py\", line 738, in _visit_func_def\r\n self.check_func_item(defn, name=defn.name)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checker.py\", line 800, in check_func_item\r\n self.check_func_def(defn, typ, name)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checker.py\", line 983, in check_func_def\r\n self.accept(item.body)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checker.py\", line 402, in accept\r\n stmt.accept(self)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/nodes.py\", line 1024, in accept\r\n return visitor.visit_block(self)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checker.py\", line 1996, in visit_block\r\n self.accept(s)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checker.py\", line 402, in accept\r\n stmt.accept(self)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/nodes.py\", line 1216, in accept\r\n return visitor.visit_if_stmt(self)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checker.py\", line 3313, in visit_if_stmt\r\n self.accept(b)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checker.py\", line 402, in accept\r\n stmt.accept(self)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/nodes.py\", line 1024, in accept\r\n return visitor.visit_block(self)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checker.py\", line 1996, in visit_block\r\n self.accept(s)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checker.py\", line 402, in accept\r\n stmt.accept(self)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/nodes.py\", line 1216, in accept\r\n return visitor.visit_if_stmt(self)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checker.py\", line 3303, in visit_if_stmt\r\n t = get_proper_type(self.expr_checker.accept(e))\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checkexpr.py\", line 3910, in accept\r\n typ = node.accept(self)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/nodes.py\", line 1663, in accept\r\n return visitor.visit_unary_expr(self)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checkexpr.py\", line 2873, in visit_unary_expr\r\n operand_type = self.accept(e.expr)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checkexpr.py\", line 3910, in accept\r\n typ = node.accept(self)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/nodes.py\", line 1600, in accept\r\n return visitor.visit_call_expr(self)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checkexpr.py\", line 277, in visit_call_expr\r\n return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checkexpr.py\", line 366, in visit_call_expr_inner\r\n ret_type = self.check_call_expr_with_callee_type(callee_type, e, fullname,\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checkexpr.py\", line 873, in check_call_expr_with_callee_type\r\n return self.check_call(callee_type, e.args, e.arg_kinds, e,\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checkexpr.py\", line 933, in check_call\r\n return self.check_callable_call(callee, args, arg_kinds, context, arg_names,\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checkexpr.py\", line 1030, in check_callable_call\r\n self.check_argument_types(arg_types, arg_kinds, args, callee, formal_to_actual, context,\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checkexpr.py\", line 1493, in check_argument_types\r\n check_arg(expanded_actual, actual_type, arg_kinds[actual],\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/checkexpr.py\", line 1523, in check_arg\r\n elif not is_subtype(caller_type, callee_type):\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/subtypes.py\", line 93, in is_subtype\r\n return _is_subtype(left, right,\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/subtypes.py\", line 147, in _is_subtype\r\n return left.accept(SubtypeVisitor(orig_right,\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/types.py\", line 1747, in accept\r\n return visitor.visit_union_type(self)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/subtypes.py\", line 476, in visit_union_type\r\n return all(self._is_subtype(item, self.orig_right) for item in left.items)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/subtypes.py\", line 476, in \u003cgenexpr>\r\n return all(self._is_subtype(item, self.orig_right) for item in left.items)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/subtypes.py\", line 205, in _is_subtype\r\n return is_subtype(left, right,\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/subtypes.py\", line 93, in is_subtype\r\n return _is_subtype(left, right,\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/subtypes.py\", line 147, in _is_subtype\r\n return left.accept(SubtypeVisitor(orig_right,\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/types.py\", line 296, in accept\r\n return visitor.visit_type_guard_type(self)\r\n File \"/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/mypy/subtypes.py\", line 479, in visit_type_guard_type\r\n raise RuntimeError(\"TypeGuard should not appear here\")\r\nRuntimeError: TypeGuard should not appear here\r\n/Users/talley/miniconda3/envs/test/lib/python3.9/site-packages/xarray/core/common.py:1659: : note: use --pdb to drop into pdb\r\n```\r\n\r\n\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 0.920+dev.7576f659d42ee271c78e69d7481b9d49517a49f6\r\n- Mypy command-line flags: `--check-untyped-defs`\r\n- Mypy configuration options from `mypy.ini` (and other config files): no config files\r\n- Python version used: 3.9.6\r\n- Operating system and version: macos 10.15.7\r\n\r\n```\r\n❯ pip list\r\nPackage Version\r\n----------------- --------------------------------------------------\r\nmypy 0.920+dev.7576f659d42ee271c78e69d7481b9d49517a49f6\r\nmypy-extensions 0.4.3\r\nnumpy 1.21.2\r\npandas 1.3.2\r\npip 21.2.4\r\npython-dateutil 2.8.2\r\npytz 2021.1\r\nsetuptools 57.4.0\r\nsix 1.16.0\r\ntomli 1.1.0\r\ntyping-extensions 3.10.0.0\r\nwheel 0.37.0\r\nxarray 0.19.0\r\n```\r\n","author":{"url":"https://github.com/tlambert03","@type":"Person","name":"tlambert03"},"datePublished":"2021-08-21T21:57:53Z","url":"https://github.com/python/mypy/issues/11007"}
| 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:c1def140-87d9-b108-467e-63fdc26a62d2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CEE0:2463C6:BC4059:FBA6D5:6B004E10 |
| html-safe-nonce | 0f89b8ac7366809bca7fb6efde98d053350dbbecbb02adcf44d019d1f06346a5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRUUwOjI0NjNDNjpCQzQwNTk6RkJBNkQ1OjZCMDA0RTEwIiwidmlzaXRvcl9pZCI6IjQ3MzQyNDI4MDAzNDQ3ODAzMDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b959b3d30907d8472d0676cd36367a954e1db52be70d8ea8373648873c8430c5 |
| hovercard-subject-tag | issue:976230025 |
| 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/11007/issue_layout |
| twitter:image | https://opengraph.githubassets.com/10f54a54fa752f0dc2dfcc4f6d2250aa72768da24d5a3a3bd4263b7d86e0a043/python/mypy/issues/11007 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/10f54a54fa752f0dc2dfcc4f6d2250aa72768da24d5a3a3bd4263b7d86e0a043/python/mypy/issues/11007 |
| og:image:alt | Crash Report Not sure whether this is a mypy issue, or an xarray issue... but I'm getting RuntimeError: TypeGuard should not appear here when running mypy on a file that imports xarray when using t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tlambert03 |
| hostname | github.com |
| expected-hostname | github.com |
| None | f9517bf360d46638a1e5e7daee7158842fe5ef43c9000afa0e127564a7c2f39b |
| 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 | b27c5dde30676028abd5c5fc53ce5c9b625f8281 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width