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 when unpacking non TypeVarTuple in args list to Callable alias #16937

Closed
hamdanal opened this issue Feb 22, 2024 · 0 comments · Fixed by #17028
Closed

Crash when unpacking non TypeVarTuple in args list to Callable alias #16937

hamdanal opened this issue Feb 22, 2024 · 0 comments · Fixed by #17028
Labels
crash topic-pep-646 PEP 646 (TypeVarTuple, Unpack) topic-type-alias TypeAlias and other type alias issues

Comments

@hamdanal
Copy link
Collaborator

Crash Report

Traceback

main.py:3: error: Name "TypeVarTuple" is not defined  [name-defined]
main.py:4: error: Variable "__main__.Ts" is not valid as a type  [valid-type]
main.py:4: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
main.py:5: error: Bad number of arguments for type alias, expected 0, given 1  [type-arg]
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.12/site-packages/mypy/__main__.py", line 37, in <module>
    console_entry()
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "/layers/google.python.pip/pip/lib/python3.12/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.12/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.12/site-packages/mypy/build.py", line 192, in build
    result = _build(
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/build.py", line 266, in _build
    graph = dispatch(sources, manager, stdout)
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/build.py", line 2942, in dispatch
    process_graph(graph, manager)
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/build.py", line 3340, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/build.py", line 3435, in process_stale_scc
    mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/semanal_main.py", line 93, in semantic_analysis_for_scc
    process_top_levels(graph, scc, patches)
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/semanal_main.py", line 220, in process_top_levels
    deferred, incomplete, progress = semantic_analyze_target(
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/semanal_main.py", line 349, in semantic_analyze_target
    analyzer.refresh_partial(
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/semanal.py", line 599, in refresh_partial
    self.refresh_top_level(node)
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/semanal.py", line 610, in refresh_top_level
    self.accept(d)
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/semanal.py", line 6588, in accept
    node.accept(self)
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/nodes.py", line 1310, in accept
    return visitor.visit_assignment_stmt(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/semanal.py", line 2919, in visit_assignment_stmt
    self.process_type_annotation(s)
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/semanal.py", line 3435, in process_type_annotation
    if analyzed is None or has_placeholder(analyzed):
                           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/semanal_shared.py", line 372, in has_placeholder
    return typ.accept(HasPlaceholders())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/types.py", line 410, in accept
    return visitor.visit_type_alias_type(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/type_visitor.py", line 550, in visit_type_alias_type
    return get_proper_type(t).accept(self)
           ^^^^^^^^^^^^^^^^^^
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/types.py", line 3085, in get_proper_type
    typ = typ._expand_once()
          ^^^^^^^^^^^^^^^^^^
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/types.py", line 352, in _expand_once
    new_tp = self.alias.target.accept(InstantiateAliasVisitor(mapping))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/types.py", line 1979, in accept
    return visitor.visit_callable_type(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/expandtype.py", line 380, in visit_callable_type
    arg_types = self.interpolate_args_for_unpack(t, var_arg.typ)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/expandtype.py", line 329, in interpolate_args_for_unpack
    assert isinstance(var_arg_type, TypeVarTupleType), type(var_arg_type)
AssertionError: <class 'mypy.types.UnboundType'>
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.10.0+dev.790e8a73d8671a41cae419b4ea07579bfb2bc292
main.py:5: : note: use --pdb to drop into pdb

To Reproduce

https://mypy-play.net/?mypy=master&python=3.12&gist=744b559e656f6f35cd5762bddf979038

# This crashes
from typing import Callable
Ts = TypeVarTuple("Ts")  # <- oops forgot to import TypeVarTuple
Alias = Callable[[*Ts], int]
x: Alias[int]
reveal_type(x)

And this

from typing import Callable, TypeVar
T = TypeVar("T")
Alias = Callable[[*T], int]
x: Alias[int]
reveal_type(x)

And this

from typing import Any, Callable
unknown: Any
Alias = Callable[[*unknown], int]
x: Alias[int]
# reveal_type(x)

Your Environment

  • Mypy version used: 1.8.0 and from the master branch
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.12
  • Operating system and version: Linux
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-type-alias TypeAlias and other type alias issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants