python / python/mypy

Feature request for something like --disallow-any-attrs

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

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

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

説明

Disclaimer: mypy newbie here, so I might just be missing something. See also my StackOverflow question for my motivation to request this feature.

Basically I couldn't find a way for mypy to require type annotations on class attributes as in the following (incomplete) example with ignore_missing_imports turned on for sqlalchemy.*.

from sqlalchemy import Column, Integer

class Foo(Base):
    oid = Column(Integer, primary_key=True)

I want code using my library (ORM definitions) to know what types they can expect. So I need mypy to make sure that oid is type annotated (e.g. oid: int = ...).

disallow_any_unimported does not seem to apply for oid. I also tried disallow_any_expr but this seems far to broad and has side-effects like causing mypy to complain about the use of Integer (Even with disallow_any_unimported = False).

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

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

はじめの一歩

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

調査の方向性

まず、SQLAlchemy Foo の例を動機となるケースとして、クラス属性に要求されている動作を既存の disallow_any_unimported オプションおよび disallow_any_expr オプションと比較します。次に、disallow_any_expr について説明されている、より広範な副作用を別のオプションでどのように回避すべきかを判断し、その後、注釈付き属性と注釈なし属性が意図した診断を生成することを確認します。

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

評価

技術スタック
python
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

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

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