Title: Crash using NamedTuple containing generic Callable · Issue #9914 · python/mypy · GitHub
Open Graph Title: Crash using NamedTuple containing generic Callable · Issue #9914 · python/mypy
X Title: Crash using NamedTuple containing generic Callable · Issue #9914 · python/mypy
Description: Crash Report Given a source file containing: class ProgressLogger(NamedTuple): progress: Callable[[T], T] where that type is used in another file as an annotation: def bar(progress_logger: ProgressLogger) -> None: pass Note that this doe...
Open Graph Description: Crash Report Given a source file containing: class ProgressLogger(NamedTuple): progress: Callable[[T], T] where that type is used in another file as an annotation: def bar(progress_logger: Progress...
X Description: Crash Report Given a source file containing: class ProgressLogger(NamedTuple): progress: Callable[[T], T] where that type is used in another file as an annotation: def bar(progress_logger: Progress...
Opengraph URL: https://github.com/python/mypy/issues/9914
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Crash using NamedTuple containing generic Callable","articleBody":"**Crash Report**\r\n\r\nGiven a source file containing:\r\n``` python\r\nclass ProgressLogger(NamedTuple):\r\n progress: Callable[[T], T]\r\n```\r\nwhere that type is used in another file as an annotation:\r\n``` python\r\ndef bar(progress_logger: ProgressLogger) -> None:\r\n pass\r\n```\r\n\r\nNote that this doesn't reproduce if the function is within the same file as the type definitions. In that case `mypy` completes without complaint.\r\n\r\n**Traceback**\r\n\r\n```\r\n# Using mypy from git at 92923b2ed8085a38c353382f805c9e2e8716e717\r\n(mypy) peter@Tarasque:mypy (master)$ mypy /tmp/repro/project/ --show-traceback\r\n/tmp/repro/project/consumer.py:4: error: INTERNAL ERROR -- Please try using mypy master on Github:\r\nhttps://mypy.rtfd.io/en/latest/common_issues.html#using-a-development-mypy-build\r\nPlease report a bug at https://github.com/python/mypy/issues\r\nversion: 0.800+dev.92923b2ed8085a38c353382f805c9e2e8716e717\r\nTraceback (most recent call last):\r\n File \"/home/peter/.virtualenvs/mypy/bin/mypy\", line 33, in \u003cmodule>\r\n sys.exit(load_entry_point('mypy', 'console_scripts', 'mypy')())\r\n File \"/home/play/mypy/mypy/__main__.py\", line 11, in console_entry\r\n main(None, sys.stdout, sys.stderr)\r\n File \"/home/play/mypy/mypy/main.py\", line 90, in main\r\n res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)\r\n File \"/home/play/mypy/mypy/build.py\", line 180, in build\r\n result = _build(\r\n File \"/home/play/mypy/mypy/build.py\", line 254, in _build\r\n graph = dispatch(sources, manager, stdout)\r\n File \"/home/play/mypy/mypy/build.py\", line 2638, in dispatch\r\n process_graph(graph, manager)\r\n File \"/home/play/mypy/mypy/build.py\", line 2964, in process_graph\r\n process_stale_scc(graph, scc, manager)\r\n File \"/home/play/mypy/mypy/build.py\", line 3056, in process_stale_scc\r\n mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)\r\n File \"/home/play/mypy/mypy/semanal_main.py\", line 79, in semantic_analysis_for_scc\r\n process_functions(graph, scc, patches)\r\n File \"/home/play/mypy/mypy/semanal_main.py\", line 233, in process_functions\r\n process_top_level_function(analyzer,\r\n File \"/home/play/mypy/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/play/mypy/mypy/semanal_main.py\", line 326, in semantic_analyze_target\r\n analyzer.refresh_partial(refresh_node,\r\n File \"/home/play/mypy/mypy/semanal.py\", line 397, in refresh_partial\r\n self.accept(node)\r\n File \"/home/play/mypy/mypy/semanal.py\", line 4835, in accept\r\n node.accept(self)\r\n File \"/home/play/mypy/mypy/nodes.py\", line 687, in accept\r\n return visitor.visit_func_def(self)\r\n File \"/home/play/mypy/mypy/semanal.py\", line 573, in visit_func_def\r\n self.analyze_func_def(defn)\r\n File \"/home/play/mypy/mypy/semanal.py\", line 602, in analyze_func_def\r\n result = analyzer.visit_callable_type(defn.type, nested=False)\r\n File \"/home/play/mypy/mypy/typeanal.py\", line 527, in visit_callable_type\r\n ret = t.copy_modified(arg_types=self.anal_array(t.arg_types, nested=nested),\r\n File \"/home/play/mypy/mypy/typeanal.py\", line 929, in anal_array\r\n res.append(self.anal_type(t, nested))\r\n File \"/home/play/mypy/mypy/typeanal.py\", line 936, in anal_type\r\n return t.accept(self)\r\n File \"/home/play/mypy/mypy/types.py\", line 490, in accept\r\n return visitor.visit_unbound_type(self)\r\n File \"/home/play/mypy/mypy/typeanal.py\", line 163, in visit_unbound_type\r\n typ = self.visit_unbound_type_nonoptional(t, defining_literal)\r\n File \"/home/play/mypy/mypy/typeanal.py\", line 252, in visit_unbound_type_nonoptional\r\n return self.analyze_type_with_type_info(node, t.args, t)\r\n File \"/home/play/mypy/mypy/typeanal.py\", line 385, in analyze_type_with_type_info\r\n return tup.copy_modified(items=self.anal_array(tup.items),\r\n File \"/home/play/mypy/mypy/typeanal.py\", line 929, in anal_array\r\n res.append(self.anal_type(t, nested))\r\n File \"/home/play/mypy/mypy/typeanal.py\", line 936, in anal_type\r\n return t.accept(self)\r\n File \"/home/play/mypy/mypy/types.py\", line 1137, in accept\r\n return visitor.visit_callable_type(self)\r\n File \"/home/play/mypy/mypy/typeanal.py\", line 526, in visit_callable_type\r\n variables = self.bind_function_type_variables(t, t)\r\n File \"/home/play/mypy/mypy/typeanal.py\", line 900, in bind_function_type_variables\r\n assert var_node, \"Binding for function type variable not found within function\"\r\nAssertionError: Binding for function type variable not found within function\r\n/tmp/repro/project/consumer.py:4: : note: use --pdb to drop into pdb\r\n```\r\n\r\n**To Reproduce**\r\n\r\nInitially observed in https://github.com/thread/django-lightweight-queue/pull/42, specifically https://github.com/thread/django-lightweight-queue/blob/7c8a2dc066acdf22bdfad88f2d2519f90155f209/django_lightweight_queue/backends/reliable_redis.py#L114-L119.\r\n\r\nCut-down to: https://gist.github.com/PeterJCLaw/00b0f5c5a5a6abcf53d2b6d6a8d142c6\r\n\r\n**Your Environment**\r\n\r\nInitially observed under Python 3.5.10, Mypy 0.770. Reproduced under Mypy 0.790.\r\nAlso reproduced on `master` at 92923b2ed8085a38c353382f805c9e2e8716e717 under Python 3.8.5.\r\n\r\nOS: Ubuntu 20.04.1.","author":{"url":"https://github.com/PeterJCLaw","@type":"Person","name":"PeterJCLaw"},"datePublished":"2021-01-15T20:06:02Z","url":"https://github.com/python/mypy/issues/9914"}
| 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:f809a139-e0a0-0ae7-d917-07b15c1dcfb0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CA7C:2B41BC:4F1585:6A46E9:6B002F41 |
| html-safe-nonce | e56eb40e15a28af87f6f28a9ca52e30ff4ec5e03da51193cfc661d3ab9d82e05 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQTdDOjJCNDFCQzo0RjE1ODU6NkE0NkU5OjZCMDAyRjQxIiwidmlzaXRvcl9pZCI6IjQxNTE5MDIxMjUxMjA2NzM5MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a29c3d9bc1ea313fbc21f1ceb446503ecce75d0b83aee1910e1b861b2109a66c |
| hovercard-subject-tag | issue:787161989 |
| 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/9914/issue_layout |
| twitter:image | https://opengraph.githubassets.com/820f0805427fea5eb9518354e2e7a000ba653d570737cc990e02c4bcc399c783/python/mypy/issues/9914 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/820f0805427fea5eb9518354e2e7a000ba653d570737cc990e02c4bcc399c783/python/mypy/issues/9914 |
| og:image:alt | Crash Report Given a source file containing: class ProgressLogger(NamedTuple): progress: Callable[[T], T] where that type is used in another file as an annotation: def bar(progress_logger: Progress... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | PeterJCLaw |
| 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