Closed
Description
Crash Report
When a asynchronous comprehension is outside of an asynchronous function, mypy crashes with an internal error. See the following example 'test.py'
test.py:
[await asyncio.sleep(1, x) for x in range(5)]
Traceback
xxm@xxm:~$ mypy --show-traceback '/home/xxm/Desktop/test.py'
/home/xxm/Desktop/test.py:1: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.0.0+dev.31b041344eab4b84971924cdcb45ba06dffe6d6c
Traceback (most recent call last):
File "/home/xxm/.local/bin/mypy", line 8, in <module>
sys.exit(console_entry())
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/__main__.py", line 15, in console_entry
main()
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/main.py", line 95, in main
res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/main.py", line 174, in run_build
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/build.py", line 194, in build
result = _build(
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/build.py", line 277, in _build
graph = dispatch(sources, manager, stdout)
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/build.py", line 2920, in dispatch
process_graph(graph, manager)
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/build.py", line 3317, in process_graph
process_stale_scc(graph, scc, manager)
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/build.py", line 3412, in process_stale_scc
mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/semanal_main.py", line 84, in semantic_analysis_for_scc
process_top_levels(graph, scc, patches)
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/semanal_main.py", line 211, in process_top_levels
deferred, incomplete, progress = semantic_analyze_target(
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/semanal_main.py", line 339, in semantic_analyze_target
analyzer.refresh_partial(
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/semanal.py", line 596, in refresh_partial
self.refresh_top_level(node)
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/semanal.py", line 607, in refresh_top_level
self.accept(d)
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/semanal.py", line 6177, in accept
node.accept(self)
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/nodes.py", line 1222, in accept
return visitor.visit_expression_stmt(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/semanal.py", line 4403, in visit_expression_stmt
s.expr.accept(self)
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/nodes.py", line 2296, in accept
return visitor.visit_list_comprehension(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/semanal.py", line 5083, in visit_list_comprehension
expr.generator.accept(self)
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/nodes.py", line 2279, in accept
return visitor.visit_generator_expr(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/semanal.py", line 5106, in visit_generator_expr
expr.left_expr.accept(self)
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/nodes.py", line 2717, in accept
return visitor.visit_await_expr(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/xxm/.local/lib/python3.11/site-packages/mypy/semanal.py", line 5172, in visit_await_expr
elif not self.function_stack[-1].is_coroutine:
~~~~~~~~~~~~~~~~~~~^^^^
IndexError: list index out of range
/home/xxm/Desktop/test.py:1: : note: use --pdb to drop into pdb
To Reproduce
- run command to install mypy: python3 -m pip install -U git+https://github.com/python/mypy.git
- run the above 'test.py' with command: mypy ----show-traceback test.py
Your Environment
- Mypy version used: 1.0.0+dev.31b041344eab4b84971924cdcb45ba06dffe6d6c
- Python version used: Python 3.11.1 [GCC 7.5.0] on linux
- Operating system and version: Ubuntu 18.04 LTS