From 86d6a96c01a3be89b5dbc0d74e5d2fb750a8b5f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sat, 25 Sep 2021 21:45:05 -0400 Subject: [PATCH 1/4] CI: run pyright with mypy --- .github/workflows/ci.yml | 8 ++++++++ .github/workflows/pre-commit.yml | 2 ++ .pre-commit-config.yaml | 2 +- ci/code_checks.sh | 7 +++++++ doc/source/development/contributing_codebase.rst | 7 ++++++- pyproject.toml | 1 - 6 files changed, 24 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 93c17997a95f7..3b30b68f64108 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,14 @@ jobs: environment-file: ${{ env.ENV_FILE }} use-only-tar-bz2: true + - name: Install node.js (for pyright) + uses: actions/setup-node@v2 + with: + node-version: "16" + + - name: Install pyright + run: npm install pyright + - name: Build Pandas uses: ./.github/actions/build_pandas diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 0609755678d78..9afb0e34f1075 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -13,6 +13,8 @@ jobs: concurrency: group: ${{ github.ref }}-pre-commit cancel-in-progress: ${{github.event_name == 'pull_request'}} + env: + SKIP: pyright steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 22c805733aff2..4331a2252ee7f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -89,7 +89,7 @@ repos: language: node pass_filenames: false types: [python] - additional_dependencies: ['pyright@1.1.170'] + additional_dependencies: ['pyright@1.1.171'] - repo: local hooks: - id: flake8-rst diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 7e4b5775af317..048f867ed377a 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -104,6 +104,13 @@ if [[ -z "$CHECK" || "$CHECK" == "typing" ]]; then MSG='Performing static analysis using mypy' ; echo $MSG mypy pandas RET=$(($RET + $?)) ; echo $MSG "DONE" + + # run pyright, if it is installed + if command -v pyright &> /dev/null ; then + MSG='Performing static analysis using pyright' ; echo $MSG + pre-commit run --all-files --hook-stage manual pyright + RET=$(($RET + $?)) ; echo $MSG "DONE" + fi fi exit $RET diff --git a/doc/source/development/contributing_codebase.rst b/doc/source/development/contributing_codebase.rst index 6fe0fa82236c3..eeba46a46dfd9 100644 --- a/doc/source/development/contributing_codebase.rst +++ b/doc/source/development/contributing_codebase.rst @@ -395,12 +395,17 @@ This module will ultimately house types for repeatedly used concepts like "path- Validating type hints ~~~~~~~~~~~~~~~~~~~~~ -pandas uses `mypy `_ to statically analyze the code base and type hints. After making any change you can ensure your type hints are correct by running +pandas uses `mypy `_ and `pyright `_ to statically analyze the code base and type hints. After making any change you can ensure your type hints are correct by running .. code-block:: shell mypy pandas + # let pre-commit setup and run pyright + pre-commit run --all-files pyright + # or if pyright is installed (requires node.js) + pyright + .. _contributing.ci: Testing with continuous integration diff --git a/pyproject.toml b/pyproject.toml index 65f49dafb5136..6b0191326518f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -139,7 +139,6 @@ reportOptionalIterable = false reportOptionalMemberAccess = false reportOptionalOperand = false reportOptionalSubscript = false -reportOverlappingOverload = false reportPrivateImportUsage = false reportPrivateUsage = false reportPropertyTypeMismatch = false From a7b0366746abe9ba08bb73d270c23100a0b1d7e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sat, 25 Sep 2021 21:58:30 -0400 Subject: [PATCH 2/4] same version --- .github/workflows/ci.yml | 3 ++- .pre-commit-config.yaml | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3b30b68f64108..b3c8bdf0501bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,8 @@ jobs: node-version: "16" - name: Install pyright - run: npm install pyright + # note: keep version in sync with .pre-commit-config.yaml + run: npm install pyright@1.1.171 - name: Build Pandas uses: ./.github/actions/build_pandas diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4331a2252ee7f..f15a340e75181 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -89,6 +89,7 @@ repos: language: node pass_filenames: false types: [python] + # note: keep version in sync with .github/workflows/ci.yml additional_dependencies: ['pyright@1.1.171'] - repo: local hooks: From 3af1f09c0bae1239593c8492d690594642b9c6ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sat, 25 Sep 2021 22:04:37 -0400 Subject: [PATCH 3/4] do not use pre-commit --- ci/code_checks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 048f867ed377a..76aae2e908de4 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -108,7 +108,7 @@ if [[ -z "$CHECK" || "$CHECK" == "typing" ]]; then # run pyright, if it is installed if command -v pyright &> /dev/null ; then MSG='Performing static analysis using pyright' ; echo $MSG - pre-commit run --all-files --hook-stage manual pyright + pyright RET=$(($RET + $?)) ; echo $MSG "DONE" fi fi From 99eb19a7d644a86d31cd9ca3141669275ecc49e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sat, 25 Sep 2021 23:09:02 -0400 Subject: [PATCH 4/4] install pyright globally --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3c8bdf0501bc..c8f5f0385732f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,7 +52,7 @@ jobs: - name: Install pyright # note: keep version in sync with .pre-commit-config.yaml - run: npm install pyright@1.1.171 + run: npm install -g pyright@1.1.171 - name: Build Pandas uses: ./.github/actions/build_pandas