`isinstance` on multiple-inheritance class erases type hints
オープン
まだ誰も着手していません。
3.12
3.13
3.14
stdlib
topic-typing
type-bug
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
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_hintson the derived class and see they are correct- check the derived class
isinstanceof the protocol get_type_hintson 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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供された再現コードを CPython で実行し、isinstance チェックの前後で get_type_hints を比較します。そのチェックに関係する get_type_hints と runtime-checkable Protocol のパスを追跡します。isinstance(t, Hello) の後も派生した Thing インスタンスが {"a": str} を報告すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100