diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eb0abe1829fc6..22c805733aff2 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.170'] - repo: local hooks: - id: 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 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..b51c0d012bfe7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -116,3 +116,47 @@ 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"] +exclude = ["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 +reportOverlappingOverload = 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