immediate numpy arguments not type checked (python 3.10)
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 38/100
調査の方向性
まず、Python 3.10 上で mypy 0.991 を使い、最終的な直接の NumPy 呼び出しと、それと同等の変数ベースの呼び出しを再現します。即時呼び出しの引数がどのように推論され、注釈付きの NDArray dtype に対してチェックされるかを追跡します。完了条件は、直接の float32-to-uint8 呼び出しが、代入された変数の場合と一貫してエラーを報告することです。
索引モデルが issue の本文から書いたものです。
説明
Bug Report
Immediate numpy parameters are not type checked. Consider the following code:
import numpy as np
def do_something_uint8(val: np.typing.NDArray[np.uint8]):
...
def do_something_float(val: np.typing.NDArray[np.float32]):
...
def scalar_int(val: int):
...
scalar_int(3.0) # correctly shows mypy error here
np_u8 = np.random.rand(3, 4).astype(np.uint8)
np_f = np.random.rand(3, 4).astype(np.float32)
do_something_uint8(np_f) # correctly shows mypy error
do_something_float(np_f)
do_something_uint8(np_u8)
do_something_float(np_u8) # correctly shows mypy error
do_something_uint8(np.random.rand(3, 4).astype(np.float32)) # does NOT show mypy error here
Look at the last line. This should show a mypy error (similar to the scalar_int case), since we are passing in a numpy with dtype float32. But it does not. If we first assign to a variable, then the type check works ok.
Expected Behavior
The last line of the code above should show a mypy error, because we are trying to pass in a numpy array with dtype float32, into a function that only accepts numpy array of dtype uint8.
Actual Behavior
The last line of the code above passes mypy checking.
Your Environment
$ python -V
Python 3.10.7
$ pip freeze | grep mypy
mypy==0.991
mypy-extensions==0.4.3
$ uname -a
Darwin Hughs-MacBook-Air.local 21.6.0 Darwin Kernel Version 21.6.0: Thu Sep 29 20:11:33 PDT 2022; root:xnu-8020.240.7~1/RELEASE_ARM64_T8110 arm64
[mypy]
ignore_missing_imports = True
No mypy command-line flags.
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 54
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/mypy のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
bug topic-configuration topic-error-reporting
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
bancolombia/sentinel#23 ·
-
test md オープンCI
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
langchain-ai/deepagents#6450 ·
-
bug client
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100