Skip to content

Protocols with self break super #12344

Closed

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

Activity

  1. henryiii commented on Sep 28, 2022

    @henryiii
    Contributor

    FYI, PyLance seems to handle this correctly; I'm not seeing this mypy error in VSCode. MyPy still does this in 0.891.

  2. added a commit that references this issue on Nov 16, 2022
    49316f9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions