From c31313095f81700888a31b276f127be658388464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Mon, 20 Sep 2021 13:50:10 -0400 Subject: [PATCH 1/8] CI: run pyright --- .pre-commit-config.yaml | 9 +++++++ pandas/core/reshape/tile.py | 2 ++ pandas/core/tools/timedeltas.py | 1 + pyproject.toml | 43 +++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eb0abe1829fc6..5a137e82cf544 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -81,6 +81,15 @@ repos: - flake8-comprehensions==3.1.0 - flake8-bugbear==21.3.2 - pandas-dev-flaker==0.2.0 +- repo: local + hooks: + - id: pyright + name: pyright + entry: pyright + language: node + pass_filenames: false + types: [python] + additional_dependencies: ['pyright@1.1.169'] - repo: local hooks: - id: flake8-rst diff --git a/pandas/core/reshape/tile.py b/pandas/core/reshape/tile.py index b1ecd75c84f4b..4ea4c055c12b0 100644 --- a/pandas/core/reshape/tile.py +++ b/pandas/core/reshape/tile.py @@ -1,6 +1,8 @@ """ Quantilization functions and related stuff """ +from __future__ import annotations + from typing import ( Any, Callable, diff --git a/pandas/core/tools/timedeltas.py b/pandas/core/tools/timedeltas.py index cbdd02aad1dd0..ca100a60a81b6 100644 --- a/pandas/core/tools/timedeltas.py +++ b/pandas/core/tools/timedeltas.py @@ -1,6 +1,7 @@ """ timedelta support tools """ +from __future__ import annotations import numpy as np diff --git a/pyproject.toml b/pyproject.toml index 03c1485bd4e35..357aabe5a6c38 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -116,3 +116,46 @@ force_grid_wrap = 2 force_sort_within_sections = true skip_glob = "env" skip = "pandas/__init__.py" + +[tool.pyright] +pythonVersion = "3.8" +typeCheckingMode = "strict" +include = ["pandas"] +ignore = ["pandas/tests"] +reportGeneralTypeIssues = false +reportConstantRedefinition = false +reportFunctionMemberAccess = false +reportImportCycles = false +reportIncompatibleMethodOverride = false +reportIncompatibleVariableOverride = false +reportInvalidStubStatement = false +reportInvalidTypeVarUse = false +reportMissingImports = false +reportMissingModuleSource = false +reportMissingTypeArgument = false +reportMissingTypeStubs = false +reportOptionalCall = false +reportOptionalIterable = false +reportOptionalMemberAccess = false +reportOptionalOperand = false +reportOptionalSubscript = false +reportPrivateImportUsage = false +reportPrivateUsage = false +reportPropertyTypeMismatch = false +reportSelfClsParameterName = false +reportUnboundVariable = false +reportUnknownArgumentType = false +reportUnknownLambdaType = false +reportUnknownMemberType = false +reportUnknownParameterType = false +reportUnknownVariableType = false +reportUnnecessaryComparison = false +reportUnnecessaryIsInstance = false +reportUnsupportedDunderAll = false +reportUntypedBaseClass = false +reportUntypedFunctionDecorator = false +reportUntypedNamedTuple = false +reportUnusedClass = false +reportUnusedFunction = false +reportUnusedImport = false +reportUnusedVariable = false From 21ebe5e82203d7b2caf5172f5ea90792e9805c93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Mon, 20 Sep 2021 16:12:57 -0400 Subject: [PATCH 2/8] ignore reportOverlappingOverload --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 357aabe5a6c38..1f6426f9ea74e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -139,6 +139,7 @@ reportOptionalIterable = false reportOptionalMemberAccess = false reportOptionalOperand = false reportOptionalSubscript = false +reportOverlappingOverload = false reportPrivateImportUsage = false reportPrivateUsage = false reportPropertyTypeMismatch = false From 56f815abb69c2fdff1912fc73103ad162fea6829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Tue, 21 Sep 2021 08:04:46 -0400 Subject: [PATCH 3/8] avoid circular dependency --- .pre-commit-config.yaml | 3 +-- pandas/core/computation/expr.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5a137e82cf544..d14cf8e2f0ad6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -89,8 +89,7 @@ repos: language: node pass_filenames: false types: [python] - additional_dependencies: ['pyright@1.1.169'] -- repo: local + additional_dependencies: ['pyright@1.1.170'] hooks: - id: flake8-rst name: flake8-rst diff --git a/pandas/core/computation/expr.py b/pandas/core/computation/expr.py index d495f89970348..de593f958922d 100644 --- a/pandas/core/computation/expr.py +++ b/pandas/core/computation/expr.py @@ -265,7 +265,10 @@ def f(self, *args, **kwargs): return f -_T = TypeVar("_T", bound="BaseExprVisitor") +# should be bound by BaseExprVisitor but that creates a circular dependency: +# _T is used in disallow, but disallow is used to define BaseExprVisitor +# https://github.com/microsoft/pyright/issues/2315 +_T = TypeVar("_T") def disallow(nodes: set[str]) -> Callable[[type[_T]], type[_T]]: @@ -279,11 +282,13 @@ def disallow(nodes: set[str]) -> Callable[[type[_T]], type[_T]]: """ def disallowed(cls: type[_T]) -> type[_T]: - cls.unsupported_nodes = () + # error: "Type[_T]" has no attribute "unsupported_nodes" + cls.unsupported_nodes = () # type: ignore[attr-defined] for node in nodes: new_method = _node_not_implemented(node) name = f"visit_{node}" - cls.unsupported_nodes += (name,) + # error: "Type[_T]" has no attribute "unsupported_nodes" + cls.unsupported_nodes += (name,) # type: ignore[attr-defined] setattr(cls, name, new_method) return cls From 89a3ff04daa41179bb0a9961065a98de66381ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Tue, 21 Sep 2021 08:16:23 -0400 Subject: [PATCH 4/8] skipped pyright? --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d14cf8e2f0ad6..22c805733aff2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -90,6 +90,7 @@ repos: pass_filenames: false types: [python] additional_dependencies: ['pyright@1.1.170'] +- repo: local hooks: - id: flake8-rst name: flake8-rst From ab76f6b4f2deb7b4a82325062e8ed900d98e812a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Fri, 24 Sep 2021 18:19:03 -0400 Subject: [PATCH 5/8] pyright is by far the slowest part of pre-commit move it to the manual stage --- .pre-commit-config.yaml | 1 + ci/code_checks.sh | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 22c805733aff2..b5b8eb2ae1f75 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -90,6 +90,7 @@ repos: pass_filenames: false types: [python] additional_dependencies: ['pyright@1.1.170'] + stages: [manual] - repo: local hooks: - id: flake8-rst diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 7e4b5775af317..67a5aedb88745 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -104,6 +104,10 @@ if [[ -z "$CHECK" || "$CHECK" == "typing" ]]; then MSG='Performing static analysis using mypy' ; echo $MSG mypy pandas RET=$(($RET + $?)) ; echo $MSG "DONE" + + MSG='Performing static analysis using pyright' ; echo $MSG + pre-commit run --hook-stage manual --all-files + RET=$(($RET + $?)) ; echo $MSG "DONE" fi exit $RET From 1994d1e94293b549c6fc177edfa6e1ce54873908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Fri, 24 Sep 2021 18:50:40 -0400 Subject: [PATCH 6/8] remove whitespace --- ci/code_checks.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 67a5aedb88745..1881b815229d0 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -104,9 +104,9 @@ if [[ -z "$CHECK" || "$CHECK" == "typing" ]]; then MSG='Performing static analysis using mypy' ; echo $MSG mypy pandas RET=$(($RET + $?)) ; echo $MSG "DONE" - + MSG='Performing static analysis using pyright' ; echo $MSG - pre-commit run --hook-stage manual --all-files + pre-commit run --all-files pyright RET=$(($RET + $?)) ; echo $MSG "DONE" fi From 142288240eb8d72ccadaee5774082884b8394eea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Fri, 24 Sep 2021 20:38:22 -0400 Subject: [PATCH 7/8] manual stage --- 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 1881b815229d0..3f98eff988257 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -106,7 +106,7 @@ if [[ -z "$CHECK" || "$CHECK" == "typing" ]]; then RET=$(($RET + $?)) ; echo $MSG "DONE" MSG='Performing static analysis using pyright' ; echo $MSG - pre-commit run --all-files pyright + pre-commit run --hook-stage manual --all-files pyright RET=$(($RET + $?)) ; echo $MSG "DONE" fi From 6df536c4839f40d2263fb2a2aee8ddf77095d843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sat, 25 Sep 2021 00:08:02 -0400 Subject: [PATCH 8/8] exclude pandas/tests --- .pre-commit-config.yaml | 1 - ci/code_checks.sh | 4 ---- pyproject.toml | 2 +- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b5b8eb2ae1f75..22c805733aff2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -90,7 +90,6 @@ repos: pass_filenames: false types: [python] additional_dependencies: ['pyright@1.1.170'] - stages: [manual] - repo: local hooks: - id: flake8-rst diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 3f98eff988257..7e4b5775af317 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -104,10 +104,6 @@ if [[ -z "$CHECK" || "$CHECK" == "typing" ]]; then MSG='Performing static analysis using mypy' ; echo $MSG mypy pandas RET=$(($RET + $?)) ; echo $MSG "DONE" - - MSG='Performing static analysis using pyright' ; echo $MSG - pre-commit run --hook-stage manual --all-files pyright - RET=$(($RET + $?)) ; echo $MSG "DONE" fi exit $RET diff --git a/pyproject.toml b/pyproject.toml index 1f6426f9ea74e..b51c0d012bfe7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -121,7 +121,7 @@ skip = "pandas/__init__.py" pythonVersion = "3.8" typeCheckingMode = "strict" include = ["pandas"] -ignore = ["pandas/tests"] +exclude = ["pandas/tests"] reportGeneralTypeIssues = false reportConstantRedefinition = false reportFunctionMemberAccess = false