python / python/mypy

no error when overriding property with incompatible return type when the overridden property has another decorator

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

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

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

説明

from contextlib import contextmanager
from typing import Iterator

@contextmanager
def foo() -> Iterator[None]:
    yield


class Bar:
    @property
    def asdf(self) -> int:
        return 2


class Baz(Bar):
    @property
    def asdf(self) -> str: # no error
        return ""

    @asdf.setter
    @foo()
    def asdf(self, new_value): ...

playground

removing the @foo() decorator makes the error appear:

main.py:16: error: Signature of "asdf" incompatible with supertype "Bar"  [override]
main.py:16: note:      Superclass:
main.py:16: note:          int
main.py:16: note:      Subclass:
main.py:16: note:          str
Found 1 error in 1 file (checked 1 source file)

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

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

はじめの一歩

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

調査の方向性

提供された Python 再現コードを実行し、@foo() を削除したバージョンと比較します。プロパティのオーバーライドチェック中にデコレートされたプロパティセッターがどのように扱われるかを追跡します。完了条件は、デコレートされたケースでも mypy が互換性のない int-to-str Override を報告することです。

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

評価

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

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

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