python / python/mypy

list of types with multiple bases only uses first shared base?

オープン
#8,513 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

feature needs discussion priority-2-low
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

i may be misunderstanding something, but it seems that when making a list of types, each with multiple shared base classes, mypy mistakenly infers this to be a list of the first base only, missing others

$ cat mypytest.py
# two different base classes with different attributes
class B1:
    b1 = None


class B2:
    b2 = None


# two classes that subclass both B1 and B2
class S1(B1, B2):
    pass


class S2(B1, B2):
    pass


# a list of the subclasses
types = [S1, S2]

# it seems mypy thinks `types` is List[Type[B1]]
ok = [x.b1 for x in types]
why_not_ok = [x.b2 for x in types]
$ mypy mypytest.py
mypytest.py:24: error: "Type[B1]" has no attribute "b2"
$ mypy --version
mypy 0.770+dev.b2edab25b7e4a6131484bb6edf314e2fa078aee7
$ python -V
Python 3.7.3

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

mypytest.py の再現コードから始め、mypy で実行して推論された型とエラーを確認します。複数の共通基底クラスを持つクラスのリストの型がどのように推論されるかを追跡し、その後、複数の基底クラスの関係を失うことなく b1 と b2 の両方が受け入れられることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
devtools
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。