Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to define a tuple with at least 1 element causes a crash if you try to define a tuple with *exactly* 1 element #16425

Closed
nytelytee opened this issue Nov 9, 2023 · 0 comments · Fixed by #16444
Labels
crash topic-pep-646 PEP 646 (TypeVarTuple, Unpack)

Comments

@nytelytee
Copy link

Crash Report

Trying to define a tuple with at least 1 element (tuple[T, *tuple[T, ...]]) causes a crash if you try to define a tuple with exactly 1 element.

Traceback

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/__main__.py", line 37, in <module>
    console_entry()
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/main.py", line 100, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/main.py", line 182, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/build.py", line 191, in build
    result = _build(
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/build.py", line 265, in _build
    graph = dispatch(sources, manager, stdout)
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/build.py", line 2943, in dispatch
    process_graph(graph, manager)
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/build.py", line 3341, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/build.py", line 3442, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/build.py", line 2311, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/checker.py", line 481, in check_first_pass
    self.accept(d)
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/checker.py", line 591, in accept
    stmt.accept(self)
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/nodes.py", line 1308, in accept
    return visitor.visit_assignment_stmt(self)
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/checker.py", line 2817, in visit_assignment_stmt
    self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/checker.py", line 2994, in check_assignment
    rvalue_type = self.check_simple_assignment(lvalue_type, rvalue, context=rvalue)
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/checker.py", line 4147, in check_simple_assignment
    rvalue_type = self.expr_checker.accept(
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/checkexpr.py", line 5716, in accept
    typ = node.accept(self)
          ^^^^^^^^^^^^^^^^^
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/nodes.py", line 2267, in accept
    return visitor.visit_tuple_expr(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/checkexpr.py", line 4929, in visit_tuple_expr
    if isinstance(type_context, TupleType) and self.tuple_context_matches(e, type_context):
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/mypy/checkexpr.py", line 4907, in tuple_context_matches
    expr_star_index = next(i for i, lv in enumerate(expr.items) if isinstance(lv, StarExpr))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
StopIteration: 

main.py:5: 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.8.0+dev.a1864d4fa498ccd8773c2247eb62282644174d26
main.py:5: : note: use --pdb to drop into pdb

To Reproduce

The line defining z in the playground is the one that causes the crash.
https://mypy-play.net/?mypy=master&python=3.12&flags=show-traceback&gist=6f394a4996dfcb54c263e1e72e3710a1

Your Environment

I don't believe any of this matters in this instance because the same issue happens on the playground as well.

@nytelytee nytelytee added the crash label Nov 9, 2023
@JelleZijlstra JelleZijlstra added the topic-pep-646 PEP 646 (TypeVarTuple, Unpack) label Nov 9, 2023
ilevkivskyi added a commit that referenced this issue Nov 10, 2023
JukkaL pushed a commit that referenced this issue Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash topic-pep-646 PEP 646 (TypeVarTuple, Unpack)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants