Skip to content

Protocols with self break super #12344

@DevilXD

Description

@DevilXD

Bug Report

Sometimes there's a need to use a typing.Protocol to specify self typing for cases like mixin classes, where the methods aren't there at class definition, but will be there at runtime, once the mixin is inherited from. This generally works fine, except it breaks in one silly case, a short repro of which is available below.

In short, it looks like super doesn't like protocols as it's second argument, which isn't even explicitly passed here.

To Reproduce

from typing import Protocol

class MixinProt(Protocol):
    def func(self) -> None:
        ...

class Mixin:
    def func(self: MixinProt) -> None:
        return super().func()

Expected Behavior

No error, duh.

Actual Behavior

From the very last line of the code above:

Argument 2 for "super" not an instance of argument 1

Your Environment

  • Mypy version used: 0.931
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.8.10
  • Operating system and version: Win7x64

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions