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 with multiple Unpack in def #16285

Closed
graingert opened this issue Oct 18, 2023 · 1 comment · Fixed by #16294
Closed

crash with multiple Unpack in def #16285

graingert opened this issue Oct 18, 2023 · 1 comment · Fixed by #16294
Labels
crash topic-pep-646 PEP 646 (TypeVarTuple, Unpack) topic-typed-dict

Comments

@graingert
Copy link
Contributor

graingert commented Oct 18, 2023

Crash Report

running with the following input:

from typing import Callable, Awaitable, TypeVar, TypedDict
from typing_extensions import TypeVarTuple, Unpack
from datetime import timedelta

T = TypeVar("T")
Ts = TypeVarTuple("Ts")

class IOLoop: pass

class EmptyDict(TypedDict):
    pass

def sync(
    loop: IOLoop,
    func: Callable[[Unpack[Ts]], Awaitable[T]],
    *args: Unpack[Ts],
    callback_timeout: str | float | timedelta | None = None,
    **kwargs: Unpack[EmptyDict],
) -> T:
    ...

Traceback

mypy --enable-incomplete-feature=TypeVarTuple --enable-incomplete-feature=Unpack --show-traceback demo.py
demo.py:13: error: Type signature has too few arguments  [misc]
demo.py:18: error: More than one Unpack in a type is not allowed  [misc]
demo.py:13: 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.7.0+dev.838a1d4be1f3cad230d028b0e9cb8e1fb7a4fa5b
Traceback (most recent call last):
  File "/home/graingert/.virtualenvs/testing311/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/home/graingert/projects/mypy/mypy/__main__.py", line 15, in console_entry
    main()
  File "/home/graingert/projects/mypy/mypy/main.py", line 99, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/home/graingert/projects/mypy/mypy/main.py", line 178, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/home/graingert/projects/mypy/mypy/build.py", line 189, in build
    result = _build(
  File "/home/graingert/projects/mypy/mypy/build.py", line 262, in _build
    graph = dispatch(sources, manager, stdout)
  File "/home/graingert/projects/mypy/mypy/build.py", line 2938, in dispatch
    process_graph(graph, manager)
  File "/home/graingert/projects/mypy/mypy/build.py", line 3336, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/home/graingert/projects/mypy/mypy/build.py", line 3431, in process_stale_scc
    mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
  File "/home/graingert/projects/mypy/mypy/semanal_main.py", line 94, in semantic_analysis_for_scc
    process_functions(graph, scc, patches)
  File "/home/graingert/projects/mypy/mypy/semanal_main.py", line 252, in process_functions
    process_top_level_function(
  File "/home/graingert/projects/mypy/mypy/semanal_main.py", line 291, in process_top_level_function
    deferred, incomplete, progress = semantic_analyze_target(
  File "/home/graingert/projects/mypy/mypy/semanal_main.py", line 349, in semantic_analyze_target
    analyzer.refresh_partial(
  File "/home/graingert/projects/mypy/mypy/semanal.py", line 606, in refresh_partial
    self.accept(node)
  File "/home/graingert/projects/mypy/mypy/semanal.py", line 6536, in accept
    node.accept(self)
  File "/home/graingert/projects/mypy/mypy/nodes.py", line 776, in accept
    return visitor.visit_func_def(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/graingert/projects/mypy/mypy/semanal.py", line 841, in visit_func_def
    self.analyze_func_def(defn)
  File "/home/graingert/projects/mypy/mypy/semanal.py", line 902, in analyze_func_def
    defn.type = set_callable_name(defn.type, defn)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/graingert/projects/mypy/mypy/semanal_shared.py", line 268, in set_callable_name
    return sig.with_name(fdef.name)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/graingert/projects/mypy/mypy/types.py", line 1955, in with_name
    return self.copy_modified(ret_type=self.ret_type, name=name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/graingert/projects/mypy/mypy/types.py", line 1875, in copy_modified
    modified = CallableType(
               ^^^^^^^^^^^^^
  File "/home/graingert/projects/mypy/mypy/types.py", line 1806, in __init__
    assert len(arg_types) == len(arg_kinds) == len(arg_names)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 
demo.py:13: : note: use --pdb to drop into pdb

To Reproduce

(Write what you did to reproduce the crash. Full source code is
appreciated. We also very much appreciate it if you try to narrow the
source down to a small stand-alone example.)

Your Environment

  • Mypy version used: 838a1d4 and 1.6.1
  • Mypy command-line flags: mypy --enable-incomplete-feature=TypeVarTuple --enable-incomplete-feature=Unpack --show-traceback
  • Mypy configuration options from mypy.ini (and other config files): no config file
  • Python version used: Python 3.11.6+
  • Operating system and version: Ubuntu 22.04.3 LTS
@AlexWaygood AlexWaygood added the topic-pep-646 PEP 646 (TypeVarTuple, Unpack) label Oct 18, 2023
@AlexWaygood
Copy link
Member

Cc. @ilevkivskyi and @jhance for PEP-646 support

ilevkivskyi added a commit that referenced this issue Oct 27, 2023
Fixes #16285

I was not sure if it is important to support this, but taking into
account the current behavior is a crash, and that implementation is
quite simple, I think we should do this. Using this opportunity I also
improve related error messages a bit.
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) topic-typed-dict
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants