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 complicated ParamSpec usage #15824

Closed
bersbersbers opened this issue Aug 6, 2023 · 3 comments
Closed

Crash on complicated ParamSpec usage #15824

bersbersbers opened this issue Aug 6, 2023 · 3 comments
Labels
crash topic-paramspec PEP 612, ParamSpec, Concatenate

Comments

@bersbersbers
Copy link

bersbersbers commented Aug 6, 2023

Crash Report

mypy crashes.

Traceback

(project_3.11) C:\Code>mypy mypy_1.5_crash.py --show-traceback
mypy_1.5_crash.py:6: error: Missing return statement  [empty-body]
mypy_1.5_crash.py:12: error: Missing return statement  [empty-body]
mypy_1.5_crash.py:11: 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.5617cdd03d12ff73622c8d4b496979e0377b1675
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Scripts\mypy.exe\__main__.py", line 7, in <module>
    sys.exit(console_entry())
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\__main__.py", line 15, in console_entry       
    main()
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\main.py", line 94, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\main.py", line 173, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\build.py", line 195, in build
    result = _build(
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\build.py", line 268, in _build
    graph = dispatch(sources, manager, stdout)
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\build.py", line 2927, in dispatch
    process_graph(graph, manager)
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\build.py", line 3325, in process_graph        
    process_stale_scc(graph, scc, manager)
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\build.py", line 3426, in process_stale_scc    
    graph[id].type_check_first_pass()
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\build.py", line 2312, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\checker.py", line 475, in check_first_pass    
    self.accept(d)
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\checker.py", line 585, in accept
    stmt.accept(self)
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\nodes.py", line 898, in accept
    return visitor.visit_decorator(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\checker.py", line 4776, in visit_decorator    
    sig, t2 = self.expr_checker.check_call(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\checkexpr.py", line 1437, in check_call
    return self.check_callable_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\checkexpr.py", line 1628, in check_callable_call
    self.check_argument_types(
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\checkexpr.py", line 2324, in check_argument_types
    check_arg(
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\checkexpr.py", line 2360, in check_arg
    elif not is_subtype(caller_type, callee_type, options=self.chk.options):
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\subtypes.py", line 177, in is_subtype
    return _is_subtype(left, right, subtype_context, proper_subtype=False)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\subtypes.py", line 332, in _is_subtype
    return left.accept(SubtypeVisitor(orig_right, subtype_context, proper_subtype))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\types.py", line 1923, in accept
    return visitor.visit_callable_type(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\subtypes.py", line 692, in visit_callable_type
    return is_callable_compatible(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\subtypes.py", line 1418, in is_callable_compatible
    unified = unify_generic_callable(left, right, ignore_return=ignore_return)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\subtypes.py", line 1725, in unify_generic_callable
    applied = mypy.applytype.apply_generic_arguments(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\applytype.py", line 170, in apply_generic_arguments
    arg_types=[expand_type(at, id_to_type) for at in callable.arg_types]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\applytype.py", line 170, in <listcomp>
    arg_types=[expand_type(at, id_to_type) for at in callable.arg_types]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\expandtype.py", line 72, in expand_type
    return typ.accept(ExpandTypeVisitor(env))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\types.py", line 1923, in accept
    return visitor.visit_callable_type(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\expandtype.py", line 435, in visit_callable_type
    arg_types = self.expand_types(t.arg_types)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\expandtype.py", line 542, in expand_types
    a.append(t.accept(self))
             ^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\types.py", line 1923, in accept
    return visitor.visit_callable_type(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\expandtype.py", line 435, in visit_callable_type
    arg_types = self.expand_types(t.arg_types)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\expandtype.py", line 542, in expand_types
    a.append(t.accept(self))
             ^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\mypy\types.py", line 1923, in accept
    return visitor.visit_callable_type(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

(last three entries repeat)

To Reproduce

Trying to investigate #15594. Code is possibly nonsense.

from typing import Callable, Concatenate, ParamSpec, TypeVar

T = TypeVar("T")
P = ParamSpec("P")

def decorator(
    caller_: Callable[Concatenate[Callable[P, T], P], T]
) -> Callable[[Callable[P, T]], Callable[P, T]]:
    ...

@decorator
def caller(callable: Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> T:
    ...

Your Environment

  • Mypy version used: mypy-1.6.0+dev.5617cdd03d12ff73622c8d4b496979e0377b1675, possibly also 1.4.1
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.11.4
  • Operating system and version: Windows
@JelleZijlstra JelleZijlstra added the topic-paramspec PEP 612, ParamSpec, Concatenate label Aug 6, 2023
@JelleZijlstra JelleZijlstra changed the title Mypy crash Crash on complicated ParamSpec usage Aug 6, 2023
@bersbersbers
Copy link
Author

bersbersbers commented Aug 9, 2023

This was briefly fixed by #15272 (until that PR was reverted). It may be a duplicate of #15388 and #15073.

@bersbersbers
Copy link
Author

582a4de from #15837 also fixes this.

@ilevkivskyi
Copy link
Member

The crash was fixed by #15837 (note the original example only works correctly with --new-type-inference).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash topic-paramspec PEP 612, ParamSpec, Concatenate
Projects
None yet
Development

No branches or pull requests

3 participants