python / python/mypy

attrs plugin does not implement the new attributes collection algorithm

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

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

bug topic-attrs
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

Bug Report

The attrs plugin does not implement the new attributes collection algorithm that is enabled with @attr.s(collect_by_mro=True) in the old API and is the only option in the new API.

To Reproduce

(mypy-play.net does not have stubs for attrs)

from attrs import define, field

@define
class A:
    f: int = field(kw_only=True)

@define
class B(A):
    pass

@define
class C(A):
    f: int = field()

@define
class D(B, C):
    pass

# D(f: int) for attrs.define, but D(*, f: int) for attr.s
d = D(123)
print(d.f)

Expected Behavior

The signature for D should be D(f: int), so this should type check. It works fine at run time.

Actual Behavior

attrs_mro.py:20: error: Too many positional arguments for "D"  [misc]

I get the same error if I replace @define and field with @attrs(collect_by_mro=True) and attrib from the old namespace respectively. Note that this behavior is correct when @attrs is used without collect_by_mro=True.

Your Environment

  • Mypy version used: 1.5.1
  • Python version used: 3.11

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

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

はじめの一歩

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

調査の方向性

mypy's attrs pluginから始め、attrs.define、field、collect_by_mro=Trueを使って報告された多重継承の例を再現します。推論されたコンストラクターシグネチャを期待されるD(f: int)の動作と比較し、位置引数による呼び出しが型チェックを通過するようにカバレッジを追加または更新し、既存のnon-collect_by_mroの動作が正しいままであることを確認します。

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

評価

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

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

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