Skip to content

Commit ff516d0

Browse files
authored
Fix numpy mypy and add mypy-next (#3995)
Towards #3767
1 parent e3fc574 commit ff516d0

File tree

5 files changed

+54
-3
lines changed

5 files changed

+54
-3
lines changed

.github/workflows/ci.yml

+17
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,25 @@ jobs:
4242
architecture: 'x64'
4343
- name: Install mypy
4444
run: cat dev_tools/conf/pip-list-dev-tools.txt | grep mypy | xargs pip install
45+
- name: Install dependencies
46+
run: pip install -r requirements.txt
4547
- name: Type check
4648
run: check/mypy
49+
mypy-next:
50+
name: Type check (next)
51+
runs-on: ubuntu-16.04
52+
steps:
53+
- uses: actions/checkout@v2
54+
- uses: actions/setup-python@v1
55+
with:
56+
python-version: '3.7'
57+
architecture: 'x64'
58+
- name: Install mypy
59+
run: cat dev_tools/conf/pip-list-dev-tools.txt | grep mypy | xargs pip install
60+
- name: Install dependencies
61+
run: pip install -r requirements.txt
62+
- name: Type check (for logging only)
63+
run: check/mypy --next || true
4764
changed_files:
4865
name: Changed files test
4966
runs-on: ubuntu-16.04

check/mypy

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@
1111
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1212
cd "$(git rev-parse --show-toplevel)"
1313

14+
config_file='mypy.ini'
15+
for arg in $@; do
16+
if [[ "${arg}" == "--next" ]]; then
17+
config_file='mypy-next.ini'
18+
shift
19+
fi
20+
done
21+
1422
echo -e -n "\033[31m"
15-
mypy --config-file=dev_tools/conf/mypy.ini $@ .
23+
mypy --config-file=dev_tools/conf/$config_file $@ .
1624
result=$?
1725
echo -e -n "\033[0m"
1826

dev_tools/conf/mypy-next.ini

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[mypy]
2+
3+
[mypy-__main__]
4+
follow_imports = silent
5+
ignore_missing_imports = true
6+
7+
# 3rd-party libs for which we don't have stubs
8+
[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.*]
9+
follow_imports = silent
10+
ignore_missing_imports = true
11+
12+
#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
13+
[mypy-sympy.*]
14+
ignore_missing_imports = True
15+
16+
# Treat symbols imported from Google's protobuf library as type Any.
17+
# This supresses errors due to attributes not known to typeshed,
18+
# e.g. Descriptor._options.
19+
[mypy-google.protobuf.*]
20+
follow_imports = skip
21+
follow_imports_for_stubs = true

dev_tools/conf/mypy.ini

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ follow_imports = silent
55
ignore_missing_imports = true
66

77
# 3rd-party libs for which we don't have stubs
8-
[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.*,importlib_metadata.*]
8+
[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.*,importlib_metadata.*]
99
follow_imports = silent
1010
ignore_missing_imports = true
1111

12+
# There was no type information before numpy 1.20, so there are numpy mypy issues in the codebase
13+
[mypy-numpy.*]
14+
follow_imports = skip
15+
follow_imports_for_stubs = true
16+
1217
#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
1318
[mypy-sympy.*]
1419
ignore_missing_imports = True

dev_tools/conf/pip-list-dev-tools.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ rstcheck~=3.3.1
3939
freezegun~=0.3.15
4040

4141
# for python 3.7 and below needs to be installed
42-
importlib-metadata; python_version < '3.8'
42+
importlib-metadata; python_version < '3.8'

0 commit comments

Comments
 (0)