Mypy does not correctly understand MemberDescriptors for objects with slots.
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 54
説明
Bug Report
When a Python object uses slots, MemberDescriptors are created for each attribute defined as a slot.
Mypy incorrectly interprets these fields as the type of the slotted value, rather than as a member descriptor.
To Reproduce
class TestObject(object):
__slots__ = ["a", "b"]
a: int
b: str
def __init__(self, a: int, b: str) -> None:
self.a = a
self.b = b
def test() -> None:
x = TestObject(5, "hi")
reveal_type(TestObject.a)
reveal_type(TestObject.b)
reveal_type(x.a)
reveal_type(x.b)
Expected Behavior
Here is what the types actually are based on the python repl.
>>> TestObject
<class '__main__.TestObject'>
>>> x = TestObject(10, "hi")
>>> type(TestObject.a)
<class 'member_descriptor'>
>>> type(TestObject.b)
<class 'member_descriptor'>
>>> type(x.a)
<class 'int'>
>>> type(x.b)
<class 'str'>
Actual Behavior
Mypy output:
12: note: Revealed type is 'builtins.int'
13: note: Revealed type is 'builtins.str'
14: note: Revealed type is 'builtins.int'
15: note: Revealed type is 'builtins.str'
Your Environment
Python 3.8.1
mypy 0.782
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供されている slots と MemberDescriptor の再現から始め、次に mypy がクラス属性とインスタンス属性について明らかにする型をどのように決定しているかを追跡します。TestObject.a と TestObject.b がメンバーディスクリプタとして報告され、x.a と x.b が int と str のままであることを確認して、修正を検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100