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

Crash on generic class with experimental TypeVarTuple support #15929

Closed
yakMM opened this issue Aug 22, 2023 · 0 comments · Fixed by #15924
Closed

Crash on generic class with experimental TypeVarTuple support #15929

yakMM opened this issue Aug 22, 2023 · 0 comments · Fixed by #15924
Labels
crash topic-pep-646 PEP 646 (TypeVarTuple, Unpack)

Comments

@yakMM
Copy link

yakMM commented Aug 22, 2023

Hello, I'm experimenting a mypy crash trying to build a generic class using TypeVarTuple (incomplete feature).

Happening on last mypy vesion 1.5.1, as well as master. Reproduction here with the master version:

Software:
Mypy version: Master: 7141d6b
Python version: 3.11.4
OS: Windows 10

Mypy command: mypy main.py --enable-incomplete-feature=TypeVarTuple --enable-incomplete-feature=Unpack --show-traceback
No config file.

Minimum reproduction code:

from typing import Generic, Unpack, TypeVarTuple
from collections.abc import Callable

ArgsT = TypeVarTuple("ArgsT")


class Foo(Generic[Unpack[ArgsT]]):
    def __init__(
        self,
        func: Callable[[Unpack[ArgsT]], None],
        *args: Unpack[ArgsT],
    ) -> None:
        self.func = func
        self.args = args

    def bar(self) -> None:
        return self.func(*self.args)  # CRASH here

Traceback:

PS D:\_projets\playground> mypy main.py --enable-incomplete-feature=TypeVarTuple --enable-incomplete-feature=Unpack --show-traceback         
main.py:17: 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.6.0+dev.7141d6bcff9e26e774e88712015ca6bbe8307c9e
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "D:\_projets\playground\.venv\Scripts\mypy.EXE\__main__.py", line 7, in <module>
    sys.exit(console_entry())
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\__main__.py", line 15, in console_entry
    main()
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\main.py", line 99, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\main.py", line 178, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\build.py", line 189, in build
    result = _build(
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\build.py", line 262, in _build
    graph = dispatch(sources, manager, stdout)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\build.py", line 2938, in dispatch
    process_graph(graph, manager)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\build.py", line 3336, in process_graph
    process_stale_scc(graph, scc, manager)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\build.py", line 3437, in process_stale_scc
    graph[id].type_check_first_pass()
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\build.py", line 2306, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checker.py", line 475, in check_first_pass
    self.accept(d)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checker.py", line 585, in accept
    stmt.accept(self)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\nodes.py", line 1145, in accept
    return visitor.visit_class_def(self)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checker.py", line 2298, in visit_class_def
    self.accept(defn.defs)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checker.py", line 585, in accept
    stmt.accept(self)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\nodes.py", line 1226, in accept
    return visitor.visit_block(self)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checker.py", line 2754, in visit_block
    self.accept(s)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checker.py", line 585, in accept
    stmt.accept(self)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\nodes.py", line 790, in accept
    return visitor.visit_func_def(self)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checker.py", line 994, in visit_func_def
    self._visit_func_def(defn)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checker.py", line 998, in _visit_func_def
    self.check_func_item(defn, name=defn.name)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checker.py", line 1071, in check_func_item
    self.check_func_def(defn, typ, name, allow_empty)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checker.py", line 1281, in check_func_def
    self.accept(item.body)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checker.py", line 585, in accept
    stmt.accept(self)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\nodes.py", line 1226, in accept
    return visitor.visit_block(self)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checker.py", line 2754, in visit_block
    self.accept(s)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checker.py", line 585, in accept
    stmt.accept(self)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\nodes.py", line 1422, in accept
    return visitor.visit_return_stmt(self)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checker.py", line 4289, in visit_return_stmt
    self.check_return_stmt(s)
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checker.py", line 4325, in check_return_stmt
    self.expr_checker.accept(
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checkexpr.py", line 5329, in accept
    typ = self.visit_call_expr(node, allow_none_return=True)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checkexpr.py", line 453, in visit_call_expr
    return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checkexpr.py", line 582, in visit_call_expr_inner
    ret_type = self.check_call_expr_with_callee_type(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checkexpr.py", line 1421, in check_call_expr_with_callee_type
    ret_type, callee_type = self.check_call(
                            ^^^^^^^^^^^^^^^^
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checkexpr.py", line 1515, in check_call
    return self.check_callable_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checkexpr.py", line 1716, in check_callable_call
    self.check_argument_types(
  File "D:\_projets\playground\.venv\Lib\site-packages\mypy\checkexpr.py", line 2413, in check_argument_types
    assert isinstance(unpacked_type, Instance)
AssertionError:
main.py:17: : note: use --pdb to drop into pdb

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