Skip to content

Commit

Permalink
Fix numpy mypy and add mypy-next (#3995)
Browse files Browse the repository at this point in the history
Towards #3767
  • Loading branch information
mpharrigan authored Apr 6, 2021
1 parent e3fc574 commit ff516d0
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,25 @@ jobs:
architecture: 'x64'
- name: Install mypy
run: cat dev_tools/conf/pip-list-dev-tools.txt | grep mypy | xargs pip install
- name: Install dependencies
run: pip install -r requirements.txt
- name: Type check
run: check/mypy
mypy-next:
name: Type check (next)
runs-on: ubuntu-16.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: '3.7'
architecture: 'x64'
- name: Install mypy
run: cat dev_tools/conf/pip-list-dev-tools.txt | grep mypy | xargs pip install
- name: Install dependencies
run: pip install -r requirements.txt
- name: Type check (for logging only)
run: check/mypy --next || true
changed_files:
name: Changed files test
runs-on: ubuntu-16.04
Expand Down
10 changes: 9 additions & 1 deletion check/mypy
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$(git rev-parse --show-toplevel)"

config_file='mypy.ini'
for arg in $@; do
if [[ "${arg}" == "--next" ]]; then
config_file='mypy-next.ini'
shift
fi
done

echo -e -n "\033[31m"
mypy --config-file=dev_tools/conf/mypy.ini $@ .
mypy --config-file=dev_tools/conf/$config_file $@ .
result=$?
echo -e -n "\033[0m"

Expand Down
21 changes: 21 additions & 0 deletions dev_tools/conf/mypy-next.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[mypy]

[mypy-__main__]
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,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

#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

# Treat symbols imported from Google's protobuf library as type Any.
# This supresses errors due to attributes not known to typeshed,
# e.g. Descriptor._options.
[mypy-google.protobuf.*]
follow_imports = skip
follow_imports_for_stubs = true
7 changes: 6 additions & 1 deletion dev_tools/conf/mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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.*,importlib_metadata.*]
[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.*]
follow_imports = silent
ignore_missing_imports = true

# There was no type information before numpy 1.20, so there are numpy mypy issues in the codebase
[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
Expand Down
2 changes: 1 addition & 1 deletion dev_tools/conf/pip-list-dev-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ rstcheck~=3.3.1
freezegun~=0.3.15

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

0 comments on commit ff516d0

Please sign in to comment.