1.6.1 > 1.7.0 and 1.7.1 regression in for "broken" ``dataclasses``

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

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

評価

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

調査の方向性

まず、issue またはそこからリンクされている mypy-playground の設定にある dataclass の例を再現し、影響を受けるバージョン間で報告される診断を比較します。誤った "B not callable" メッセージを生成している dataclass の処理を追跡します。完了条件は、例が期待どおり不足している attr_two 引数のみを報告することです。

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

説明

bug topic-dataclasses

Bug Report

When type checking the following code the output changes depending on whether you use 1.6.0 or 1.7.1.

To Reproduce

from dataclasses import dataclass


@dataclass(frozen=True)
class A:
    attr_one: int
    attr_two: int | None


@dataclass(frozen=True)
class B(A):
    attr_two = None


instance = B(attr_one=1)
print(instance.attr_two)

Playground: https://mypy-play.net/?mypy=1.7.0&python=3.11&gist=f74740e7a7ef6bf0c9f88175a988aed5

The code is likely not doing what the author expects it to do, but the new message is wrong as attr_two can be referenced and is certainly not an instance of B.

Expected Behavior

main.py:15: error: Missing positional argument "attr_two" in call to "B"  [call-arg]
Found 1 error in 1 file (checked 1 source file)

Actual Behavior

main.py:15: error: Missing positional argument "attr_two" in call to "B"  [call-arg]
main.py:16: error: "B" not callable  [operator]
Found 2 errors in 1 file (checked 1 source file)

Your Environment
master branch on Playground.

主要言語
Python
スター
20.6k
フォーク
3.3k
平均マージ
1日 18時間
マージ済み PR(30日)
54

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

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

はじめの一歩

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

python/mypy のほかの issue

python/mypy の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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