immediate numpy arguments not type checked (python 3.10)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 38/100
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện lệnh gọi NumPy trực tiếp cuối cùng và các lệnh gọi tương đương dựa trên biến bằng mypy 0.991 trên Python 3.10. Theo dõi cách các đối số của lệnh gọi tức thời được suy luận và kiểm tra so với dtype được chú thích của NDArray; hoàn tất khi lệnh gọi trực tiếp từ float32-to-uint8 báo lỗi nhất quán với trường hợp biến được gán.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 20.6k
- Fork
- 3.3k
- Merge trung bình
- 1 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 54
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python/mypy
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
bug topic-configuration topic-error-reporting
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
zostera/django-bootstrap4#894 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
use-agent-os/agent-os#3276 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NousResearch/hermes-agent#117848 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
zilliztech/memsearch#759 ·