Crash on unpacked tuple in tuple type definition
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Crash Report
Mypy 1.20.2 is crashing when processing type definition of a tuple that unpacks another tuple. I have a reproducer on mypy-play with latest version (2.3.1). See https://mypy-play.net/?gist=43e256f314819d34c14f92b9098ed40c
Traceback
mre.py:12: 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.20.2
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "mypy/checkexpr.py", line 6092, in accept
File "mypy/checkexpr.py", line 6127, in accept_maybe_cache
File "mypy/nodes.py", line 2469, in accept
File "mypy/checkexpr.py", line 502, in visit_call_expr
File "mypy/checkexpr.py", line 639, in visit_call_expr_inner
File "mypy/checkexpr.py", line 1489, in check_call_expr_with_callee_type
File "mypy/checkexpr.py", line 1593, in check_call
File "mypy/checkexpr.py", line 2749, in check_overload_call
File "mypy/checkexpr.py", line 2917, in infer_overload_return_type
File "mypy/checkexpr.py", line 1582, in check_call
File "mypy/checkexpr.py", line 1747, in check_callable_call
File "mypy/checkexpr.py", line 2060, in infer_function_type_arguments_using_context
File "mypy/checkexpr.py", line 3292, in apply_generic_arguments
File "mypy/applytype.py", line 115, in apply_generic_arguments
File "mypy/applytype.py", line 79, in get_target_type
File "mypy/subtypes.py", line 189, in is_subtype
File "mypy/subtypes.py", line 363, in _is_subtype
File "mypy/types.py", line 2818, in accept
File "mypy/subtypes.py", line 798, in visit_tuple_type
File "mypy/typeops.py", line 119, in tuple_fallback
NotImplementedError:
mre.py:12: note: use --pdb to drop into pdb
To Reproduce
See https://mypy-play.net/?gist=43e256f314819d34c14f92b9098ed40c
"""
Minimal reproducer: mypy 1.20.2 (and latest 2.3.1) crashes on a nested tuple type alias unpack.
"""
from collections import deque
type Inner = tuple[int, str]
type Outer = tuple[bool, *Inner]
class K(Base):
q: deque[Outer] = deque()
class Base: ...
Your Environment
- Mypy version used: 1.20.2 and 2.3.1
- Mypy command-line flags:
python -m mypy --python-version 3.12 --no-incremental --cache-dir=/dev/null --show-traceback mre.py - Python version used: Python 3.12.13
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied reproducer and command, then trace the reported path through mypy/checkexpr.py, mypy/applytype.py, mypy/subtypes.py, mypy/types.py, and mypy/typeops.py. Confirm the nested tuple alias in deque[Outer] no longer raises an INTERNAL ERROR or traceback, and add or update regression coverage where the project’s existing tests for this type-checking path belong.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100