Skip to content

stubgen removes Protocol from base classes list #12072

@citruz

Description

@citruz

Bug Report

Consider the following input:

from typing import Protocol

class Interface(Protocol):
    def dummy(self, arg: str) -> str:
        ...

stubgen produces:

class Interface:
    def dummy(self, arg: str) -> str: ...

Note that the Protocol class is removed from the list of base classes.

Obviously this causes problems when performing type checking against users of that generated typestub:

from interface import Interface

class InterfaceImpl:
    def dummy(self, arg: str) -> str:
        return arg


interf: Interface = InterfaceImpl()

mypy:

provider/__init__.py:8: error: Incompatible types in assignment (expression has type "InterfaceImpl", variable has type "Interface")

Expected Behavior

Protocol base class is not removed.

Actual Behavior

Protocol base class is removed.

Your Environment

  • Mypy version used: mypy 0.931
  • Python version used: Python 3.9.7
  • Operating system and version: macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions