python / python/mypy

No error when attempting to use property object as that property's type

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

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

priority-2-low topic-descriptors topic-named-tuple topic-runtime-semantics
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

  • Are you reporting a bug, or opening a feature request? Bug
  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.
from typing import NamedTuple


class C(NamedTuple):
    a: int = 1


print(C.a * 2)
  • What is the actual behavior/output?

mypy a.py produces no output.

  • What is the behavior/output you expect?

An error at C.a * 2, as it will cause an error at runtime: TypeError: unsupported operand type(s) for *: 'property' and 'int'

  • What are the versions of mypy and Python you are using?

python --version: 3.7.2
mypy --version: 0.660+dev.97d7760dca6d95806a97b02992ae88a082898a0e

Do you see the same issue after installing mypy from Git master? Yes

  • What are the mypy flags you are using? (For example --strict-optional) None

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

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

はじめの一歩

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

調査の方向性

まず、報告された例を使って mypy a.py を実行し、出力がない一方で Python は指定された TypeError を発生させることを確認します。mypy が NamedTuple のプロパティアクセスと算術式をどのように処理するかを追跡します。このケースで mypy が C.a * 2 に対してエラーを報告すれば完了です。

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

評価

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

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

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