False positive on re.compile as attrs converter
オープン
まだ誰も着手していません。
bug
false-positive
priority-1-normal
topic-attrs
topic-type-variables
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
I've found what I think is a bug in mypy's attrs support.
# test.py
import re
import attr
@attr.s
class Test:
foo = attr.ib(converter=re.compile)
test = Test("foo")
$ mypy test.py
test.py:8: error: Argument 1 to "Test" has incompatible type "str"; expected "Union[AnyStr, Pattern[AnyStr]]"
Unless I've completely misunderstood what AnyStr is for, I don't think that signature should throw on receiving a string.
I can't quite figure out if attrs or mypy is at fault here, but I can't get the same error to appear on re.compile when it's not being applied as a converter by attrs. Apologies if I've missed an obvious issue here.
Python v3.6.5
Mypy v0.610
Attrs v18.1.0
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
示されている test.py を使ってまず報告を再現し、re.compile 単体の場合の mypy の処理と、attrs のコンバーターとして扱った場合の処理を比較してください。attrs コンバーターの型推論と、それによって行われるコンストラクター引数のチェックを追跡してください。Test("foo") が、有効なコンバーターの型付けを弱めることなく受け入れられれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100