Skip to content

Crash on a tricky overloaded Protocol #17206

Closed
@Suor

Description

Crash Report

A crash happens while using _W wrapper below, which is a cut down version of functools._Wrapped.

Traceback

_broken.pyi: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.10.0
Traceback (most recent call last):
  File "mypy/checker.py", line 589, in accept
  File "mypy/nodes.py", line 586, in accept
  File "mypy/checker.py", line 626, in visit_overloaded_func_def
  File "mypy/checker.py", line 656, in _visit_overloaded_func_def
  File "mypy/checker.py", line 767, in check_overlapping_overloads
  File "mypy/checker.py", line 7813, in is_unsafe_overlapping_overload_signatures
  File "mypy/subtypes.py", line 1521, in is_callable_compatible
  File "mypy/subtypes.py", line 1862, in unify_generic_callable
  File "mypy/constraints.py", line 311, in infer_constraints
  File "mypy/constraints.py", line 407, in _infer_constraints
  File "mypy/types.py", line 1444, in accept
  File "mypy/constraints.py", line 802, in visit_instance
  File "mypy/constraints.py", line 314, in infer_constraints
  File "mypy/constraints.py", line 407, in _infer_constraints
  File "mypy/types.py", line 1730, in accept
  File "mypy/constraints.py", line 698, in visit_parameters
RuntimeError: Parameters cannot be constrained to
_broken.pyi:13: : note: use --pdb to drop into pdb

_broken.pyi:

from typing import Callable, Generic, ParamSpec, Protocol, TypeVar, overload

_PD = ParamSpec('_PD')
_PF = ParamSpec('_PF')
_RD = TypeVar('_RD')
_RF = TypeVar('_RF')

# from functools import _Wrapped as _W
class _W(Generic[_PF, _RF, _PD, _RD]):
    ...

class _DecoOrFab(Protocol[_PD, _RD]):
    @overload
    def __call__(self, f: Callable[_PF, _RF]) -> _W[_PF, _RF, ..., _RD]: ...
    @overload
    def __call__(self, **kwargs) -> _W[_PD, _RD, ..., ...]: ...

Your Environment

  • Mypy version used: 1.10.0
  • Mypy command-line flags: mypy --show-traceback _broken.pyi
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.11.8
  • Operating system and version: Linux, 6.6.26-1-MANJARO, x86_64 GNU/Linux

mypy.ini:

[mypy]
python_version = 3.11
check_untyped_defs = true
; disallow_untyped_calls = true
ignore_errors = false
ignore_missing_imports = true
warn_unused_ignores = true
warn_redundant_casts = true
warn_unused_configs = true
follow_imports = silent
disable_error_code = var-annotated

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions