Skip to content

INTERNAL ERROR when using typing.ParamSpec #16257

Closed

Description

@evhub

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

Activity

  1. AlexWaygood commented on Oct 13, 2023

    @AlexWaygood
    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:
  2. AlexWaygood commented on Oct 13, 2023

    @AlexWaygood
    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)

  3. ilevkivskyi commented on Oct 13, 2023

    @ilevkivskyi
    Member

    Fix in #16257

  4. ilevkivskyi commented on Oct 13, 2023

    @ilevkivskyi
    Member

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

  5. hauntsaninja commented on Oct 13, 2023

    @hauntsaninja
    Collaborator

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

  6. evhub commented on Oct 13, 2023

    @evhub
    ContributorAuthor

    @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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions