Type checking unexpectedly passing when misusing `default` and `converter`
まだ誰も着手していません。
評価
調査の方向性
Start by running the Python 2/3 reproducer and checking the reported MyPy diagnostics for A, especially the y attribute using default=None and _convert_int. Trace whether the missing error belongs to attrs' generated typing information or to MyPy/Typeshed, and consider the issue done when the ownership and a regression check for this case are established.
索引モデルが issue の本文から書いたものです。
説明
I was playing around with type annotations and Attrs, and I think I may have found an issue.
Given the following Python 2/3 script:
from __future__ import absolute_import
from pprint import pprint as pp
import attr
def _convert_int(val):
# type: (int) -> int
if val <= 0:
return -1
return val
@attr.s
class A(object):
x = attr.ib(default=0, converter=_convert_int, type=int)
y = attr.ib(default=None, converter=_convert_int, type=int) # `default` is incompatible with our declared `type`
def main():
# type: () -> None
a1 = A(5, 5) # correct: type checks
pp(a1)
a2 = A(5, None) # correct: doesn't type check
pp(a2)
a3 = A(5) # incorrect: type checks but shouldn't!
pp(a3)
if __name__ == '__main__':
main()
I'd expect MyPy to complain about the relationship between default and converter for y. Nevertheless, I'm getting:

Which is one error less than expected.
Should I perhaps report this to MyPy or Typeshed as well/instead?
- 主要言語
- Python
- スター
- 5.8k
- フォーク
- 480
- 平均マージ
- 2時間 15分
- マージ済み PR(30日)
- 2
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python-attrs/attrs のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
python-attrs/attrs#1620 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
python-attrs/attrs#1596 · コメント 2 件 · リアクション 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
python-attrs/attrs#1549 · コメント 3 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
python-attrs/attrs#1543 · コメント 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
python-attrs/attrs#1532 ·
python-attrs/attrs の issue をすべて見る
似ている issue
-
area: harness bug status: needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Human-Agent-Society/reef#625 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
learningequality/kolibri#15351 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
Name consistency オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
eellak/triplestore#65 · コメント 1 件 ·