Skip to content

isinstance on multiple-inheritance class erases type hints #124840

@coretl

Description

@coretl

Bug report

Bug description:

Steps to reproduce:

  • Create a runtime checkable protocol
  • Create one base class with type hints
  • Create a second base class that satisfies the protocol
  • Create a derived class that inherits from both the base classes
  • get_type_hints on the derived class and see they are correct
  • check the derived class isinstance of the protocol
  • get_type_hints on the derived class and see that they are a blank dictionary
from abc import abstractmethod
from typing import Protocol, get_type_hints, runtime_checkable

@runtime_checkable
class Hello(Protocol):
    @abstractmethod
    def hello(self) -> str: ...

class Base:
    a: str

class Base2:
    def hello(self) -> str:
        return "hello"

class Thing(Base, Base2): ...

def test_hints():
    t = Thing()
    assert get_type_hints(t) == {"a": str}
    assert isinstance(t, Hello)
    assert get_type_hints(t) == {"a": str}

CPython versions tested on:

3.11, 3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions