immediate numpy arguments not type checked (python 3.10)
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 38/100
Piste de recherche
Commencez par reproduire l’appel direct final à NumPy et les appels équivalents fondés sur des variables avec mypy 0.991 sous Python 3.10. Suivez la manière dont les arguments des appels immédiats sont inférés et vérifiés par rapport au dtype annoté de NDArray ; c’est terminé lorsque l’appel direct de float32-to-uint8 signale une erreur de manière cohérente avec le cas de la variable assignée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Python
- Étoiles
- 20.6k
- Forks
- 3.3k
- Merge moyen
- 1 j 18 h
- PR mergées (30 j)
- 54
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de python/mypy
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
bug topic-configuration topic-error-reporting
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Toutes les issues de python/mypy
Issues similaires
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
zostera/django-bootstrap4#894 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
use-agent-os/agent-os#3276 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
NousResearch/hermes-agent#117848 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
zilliztech/memsearch#759 ·