-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Numpy 1.20 includes typing information, breaks mypy checks locally #3767
Comments
Probably a Python 3.9 issue. |
I just started seeing this and was wondering whether it's only my machine. I'm on python 3.8 but I've seen it on python 3.7. I wonder why the CI is not catching it. |
This is because of the release of numpy 1.20, which added type annotations |
This isn't picked up by the CI since we don't install cirq or its requirements during the mypy check |
diff --git a/dev_tools/conf/mypy.ini b/dev_tools/conf/mypy.ini
index f931717b..6fbc7276 100644
--- a/dev_tools/conf/mypy.ini
+++ b/dev_tools/conf/mypy.ini
@@ -5,10 +5,15 @@ follow_imports = silent
ignore_missing_imports = true
# 3rd-party libs for which we don't have stubs
-[mypy-apiclient.*,freezegun.*,matplotlib.*,mpl_toolkits,multiprocessing.dummy,numpy.*,oauth2client.*,pandas.*,pytest.*,scipy.*,sortedcontainers.*,setuptools.*,pylatex.*,networkx.*,qiskit.*,pypandoc.*,ply.*,_pytest.*,google.api.*,google.api_core.*,grpc.*,google.oauth2.*,google.protobuf.text_format.*,quimb.*,pyquil.*,google.cloud.*,filelock.*,codeowners.*,tqdm.*]
+[mypy-apiclient.*,freezegun.*,matplotlib.*,mpl_toolkits,multiprocessing.dummy,oauth2client.*,pandas.*,pytest.*,scipy.*,sortedcontainers.*,setuptools.*,pylatex.*,networkx.*,qiskit.*,pypandoc.*,ply.*,_pytest.*,google.api.*,google.api_core.*,grpc.*,google.oauth2.*,google.protobuf.text_format.*,quimb.*,pyquil.*,google.cloud.*,filelock.*,codeowners.*,tqdm.*]
follow_imports = silent
ignore_missing_imports = true
+# There was no type information before numpy 1.20
+[mypy-numpy.*]
+follow_imports = skip
+follow_imports_for_stubs = true
+
#Adding "sympy.* or mypy-sympy to the above list (3rd-party libs for which we don't have stubs) doesn't ignore "cannot find module 'sympy' error
[mypy-sympy.*]
ignore_missing_imports = True silences it |
Thanks for the research on this and silencing tip @mpharrigan! I believe that we should slowly chip away at this though - there is a reason why we have mypy - thus if we believe in the usefulness of type checking, we are behooved to follow through with fixing these issues and then turn it on on CI (by installing the correct requirements). |
What's the plan for this? I'm getting agita from having my uncomitted |
FWIW we've internally used the |
+1 to that approach - @mpharrigan do you want to implement it? |
Do you have a failing check and have github ignore the result or do you put |
#3995 updates the CI. Of course: there is still the issue of fixing all the numpy problems |
Using `check/mypy --next | grep cirq/ops` this fixes almost all of the issues raised with simple modifications. There is a looming problem with places where we use `numbers.Complex`, which is a nice generalization for Union[int, float, complex] but does not play nice with numpy type information. Towards #3767
Using `check/mypy --next | grep cirq/linalg` this fixes all the problems. #3767
Changing to kind/health instead of kind/bug-report since nothing is currently broken |
Having said that, I see that |
What is the goal for before-1.0 here? I made progress on fixing the numpy errors in |
Discussion from cirq cync: this is a nice to have for cirq 1.0, since typing changes could theoretically change the API interface, but these would likely be small changes and may not materialize. We will keep it on before 1.0 for now, but if we run out of time, this is a good candidate to cut. |
Will push changes to github actions after this is in. * `np.einsum` is missing a type signature, resulting in some type ignores (filed issue at numpy numpy/numpy#21978) * In practice one can use numpy types like np.double for parameters, but currently we don't support that. Filed #5758 to consider this. * Numpy `tolist` does not return a type signature of `List`. wat? Part of #3767
12 errors left Part of quantumlib#3767
Will push changes to github actions after this is in. * `np.einsum` is missing a type signature, resulting in some type ignores (filed issue at numpy numpy/numpy#21978) * In practice one can use numpy types like np.double for parameters, but currently we don't support that. Filed quantumlib#5758 to consider this. * Numpy `tolist` does not return a type signature of `List`. wat? Part of quantumlib#3767
12 errors left Part of quantumlib#3767
Will push changes to github actions after this is in. * `np.einsum` is missing a type signature, resulting in some type ignores (filed issue at numpy numpy/numpy#21978) * In practice one can use numpy types like np.double for parameters, but currently we don't support that. Filed quantumlib#5758 to consider this. * Numpy `tolist` does not return a type signature of `List`. wat? Part of quantumlib#3767
Description of the issue
mypy encounters errors.
How to reproduce the issue
In a fresh virtual environment, install Cirq and the dev tools (mypy version 0.782). Then execute
This gives the following errors:
Cirq version
f08b344
The text was updated successfully, but these errors were encountered: