diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4303c39d1f2..2b342242a6c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/check/mypy b/check/mypy index ef2fe08ed2f..a3b068fdb3c 100755 --- a/check/mypy +++ b/check/mypy @@ -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" diff --git a/dev_tools/conf/mypy-next.ini b/dev_tools/conf/mypy-next.ini new file mode 100644 index 00000000000..ddc541248a6 --- /dev/null +++ b/dev_tools/conf/mypy-next.ini @@ -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 diff --git a/dev_tools/conf/mypy.ini b/dev_tools/conf/mypy.ini index 6e82df06b44..63329e39973 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.*,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 diff --git a/dev_tools/conf/pip-list-dev-tools.txt b/dev_tools/conf/pip-list-dev-tools.txt index 623e3925b3f..e5eafb200f9 100644 --- a/dev_tools/conf/pip-list-dev-tools.txt +++ b/dev_tools/conf/pip-list-dev-tools.txt @@ -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' \ No newline at end of file