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

INTERNAL ERROR when using typing.ParamSpec #16257

Closed
evhub opened this issue Oct 13, 2023 · 6 comments · Fixed by #16259
Closed

INTERNAL ERROR when using typing.ParamSpec #16257

evhub opened this issue Oct 13, 2023 · 6 comments · Fixed by #16259
Labels
crash topic-paramspec PEP 612, ParamSpec, Concatenate

Comments

@evhub
Copy link
Contributor

evhub commented Oct 13, 2023

Crash Report

MyPy INTERNAL ERROR when running reproduction code below.

Traceback

break_mypy.py:32: error: An overloaded function outside a stub file must have an implementation  [no-overload-impl]
break_mypy.py:32: 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
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "mypy\checker.py", line 585, in accept
  File "mypy\nodes.py", line 588, in accept
  File "mypy\checker.py", line 622, in visit_overloaded_func_def
  File "mypy\checker.py", line 652, in _visit_overloaded_func_def
  File "mypy\checker.py", line 762, in check_overlapping_overloads
  File "mypy\checker.py", line 7268, in is_unsafe_overlapping_overload_signatures
  File "mypy\subtypes.py", line 1425, in is_callable_compatible
  File "mypy\subtypes.py", line 1749, in unify_generic_callable
  File "mypy\applytype.py", line 129, in apply_generic_arguments
  File "mypy\expandtype.py", line 71, in expand_type
  File "mypy\types.py", line 1953, in accept
  File "mypy\expandtype.py", line 342, in visit_callable_type
  File "mypy\types.py", line 1877, in copy_modified
  File "mypy\types.py", line 1811, in __init__
AssertionError:
break_mypy.py:32: : note: use --pdb to drop into pdb

To Reproduce

Reproduction code:

from typing import *

_T = TypeVar("_T")
_U = TypeVar("_U")
_V = TypeVar("_V")
_W = TypeVar("_W")
_P = ParamSpec("_P")

@overload
def call(
    _func: Callable[Concatenate[_T, _P], _U],
    _x: _T,
    *args: Any,
    **kwargs: Any,
) -> _U: ...
@overload
def call(
    _func: Callable[Concatenate[_T, _U, _P], _V],
    _x: _T,
    _y: _U,
    *args: Any,
    **kwargs: Any,
) -> _V: ...

Your Environment

  • Mypy version used: mypy 1.6.0 (compiled: yes)
  • Mypy command-line flags: --show-traceback
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: Python 3.11.4
  • Operating system and version: Windows 11
@evhub evhub added the crash label Oct 13, 2023
@AlexWaygood AlexWaygood added the topic-paramspec PEP 612, ParamSpec, Concatenate label Oct 13, 2023
@AlexWaygood
Copy link
Member

I confirmed that this still reproduces on master, and with the latest version of the release-1.6 branch. Here's the stack trace on the master branch, using uncompiled mypy:

break_mypy.py:9: error: An overloaded function outside a stub file must have an implementation  [no-overload-impl]
break_mypy.py:9: 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.72605dc12a89b9c12a502ebfad494b4b9d9b5160
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\alexw\coding\mypy\venv\Scripts\mypy.exe\__main__.py", line 7, in <module>
    sys.exit(console_entry())
  File "C:\Users\alexw\coding\mypy\mypy\__main__.py", line 15, in console_entry
    main()
  File "C:\Users\alexw\coding\mypy\mypy\main.py", line 99, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "C:\Users\alexw\coding\mypy\mypy\main.py", line 178, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "C:\Users\alexw\coding\mypy\mypy\build.py", line 189, in build
    result = _build(
  File "C:\Users\alexw\coding\mypy\mypy\build.py", line 262, in _build
    graph = dispatch(sources, manager, stdout)
  File "C:\Users\alexw\coding\mypy\mypy\build.py", line 2938, in dispatch
    process_graph(graph, manager)
  File "C:\Users\alexw\coding\mypy\mypy\build.py", line 3336, in process_graph
    process_stale_scc(graph, scc, manager)
  File "C:\Users\alexw\coding\mypy\mypy\build.py", line 3437, in process_stale_scc
    graph[id].type_check_first_pass()
  File "C:\Users\alexw\coding\mypy\mypy\build.py", line 2306, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "C:\Users\alexw\coding\mypy\mypy\checker.py", line 477, in check_first_pass
    self.accept(d)
  File "C:\Users\alexw\coding\mypy\mypy\checker.py", line 587, in accept
    stmt.accept(self)
  File "C:\Users\alexw\coding\mypy\mypy\nodes.py", line 575, in accept
    return visitor.visit_overloaded_func_def(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\alexw\coding\mypy\mypy\checker.py", line 624, in visit_overloaded_func_def
    self._visit_overloaded_func_def(defn)
  File "C:\Users\alexw\coding\mypy\mypy\checker.py", line 654, in _visit_overloaded_func_def
    self.check_overlapping_overloads(defn)
  File "C:\Users\alexw\coding\mypy\mypy\checker.py", line 764, in check_overlapping_overloads
    if is_unsafe_overlapping_overload_signatures(sig1, sig2, type_vars):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\alexw\coding\mypy\mypy\checker.py", line 7353, in is_unsafe_overlapping_overload_signatures
    return is_callable_compatible(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\alexw\coding\mypy\mypy\subtypes.py", line 1484, in is_callable_compatible
    unified = unify_generic_callable(
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\alexw\coding\mypy\mypy\subtypes.py", line 1821, in unify_generic_callable
    applied = mypy.applytype.apply_generic_arguments(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\alexw\coding\mypy\mypy\applytype.py", line 129, in apply_generic_arguments
    arg_types=[expand_type(at, id_to_type) for at in callable.arg_types]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\alexw\coding\mypy\mypy\applytype.py", line 129, in <listcomp>
    arg_types=[expand_type(at, id_to_type) for at in callable.arg_types]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\alexw\coding\mypy\mypy\expandtype.py", line 71, in expand_type
    return typ.accept(ExpandTypeVisitor(env))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\alexw\coding\mypy\mypy\types.py", line 1954, in accept
    return visitor.visit_callable_type(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\alexw\coding\mypy\mypy\expandtype.py", line 350, in visit_callable_type
    return t.copy_modified(
           ^^^^^^^^^^^^^^^^
  File "C:\Users\alexw\coding\mypy\mypy\types.py", line 1878, in copy_modified
    modified = CallableType(
               ^^^^^^^^^^^^^
  File "C:\Users\alexw\coding\mypy\mypy\types.py", line 1812, in __init__
    assert not t.prefix.arg_types
AssertionError:

@AlexWaygood
Copy link
Member

14418bc3d2c38b9ea776da6029e9d9dc6650b7ea is the first bad commit
commit 14418bc3d2c38b9ea776da6029e9d9dc6650b7ea
Author: Ivan Levkivskyi <levkivskyi@gmail.com>
Date:   Tue Aug 15 20:31:26 2023 +0100

    Polymorphic inference: support for parameter specifications and lambdas (#15837)

14418bc again (cc. @ilevkivskyi)

@ilevkivskyi
Copy link
Member

Fix in #16257

@ilevkivskyi
Copy link
Member

This is essentially the same story as the other two crashes.

ilevkivskyi added a commit that referenced this issue Oct 13, 2023
Fixes #16257

Parenthesis strike back. I hope this is the last place where I had put
them wrong.
@hauntsaninja
Copy link
Collaborator

@evhub Thanks for coconut! Did you encounter the regression on an open source codebase?

@evhub
Copy link
Contributor Author

evhub commented Oct 13, 2023

@hauntsaninja Thanks! And yep, it showed up in Coconut's type stub for call: https://github.com/evhub/coconut/blob/master/__coconut__/__init__.pyi#L256

hauntsaninja pushed a commit that referenced this issue Oct 17, 2023
Fixes #16257

Parenthesis strike back. I hope this is the last place where I had put
them wrong.
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

Successfully merging a pull request may close this issue.

4 participants