diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 37af401..84b7ec8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-added-large-files - id: check-toml @@ -10,20 +10,20 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/asottile/pyupgrade - rev: v3.6.0 + rev: v3.15.0 hooks: - id: pyupgrade args: - --py3-plus - --keep-runtime-typing - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.272 + rev: v0.1.11 hooks: - id: ruff args: - --fix - repo: https://github.com/pycqa/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort name: isort (python) @@ -31,9 +31,16 @@ repos: name: isort (pyi) types: [pyi] - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 23.12.1 hooks: - id: black + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.8.0 + hooks: + - id: mypy + additional_dependencies: + - pandas-stubs + exclude: ^tests/.*$ - repo: local hooks: - id: rust-linting diff --git a/pyproject.toml b/pyproject.toml index 753f426..4d8b7aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,6 +18,12 @@ line_length = 88 multi_line_output = 3 profile = "black" +[tool.mypy] +python_version = "3.8" +ignore_missing_imports = false +disallow_untyped_defs = true +check_untyped_defs = true + [build-system] requires = ["maturin>=1,<2"] build-backend = "maturin" diff --git a/python/python_calamine/_python_calamine.pyi b/python/python_calamine/_python_calamine.pyi index 62caaf2..37e0e03 100644 --- a/python/python_calamine/_python_calamine.pyi +++ b/python/python_calamine/_python_calamine.pyi @@ -8,8 +8,8 @@ from typing import Protocol ValueT = int | float | str | bool | time | date | datetime | timedelta class ReadBuffer(Protocol): - def seek(self) -> int: ... - def read(self) -> bytes: ... + def seek(self, __offset: int, __whence: int = ...) -> int: ... + def read(self, __size: int = ...) -> bytes | None: ... class SheetTypeEnum(enum.Enum): WorkSheet = ... diff --git a/python/python_calamine/pandas.py b/python/python_calamine/pandas.py index d3ca00b..6bf15b3 100644 --- a/python/python_calamine/pandas.py +++ b/python/python_calamine/pandas.py @@ -10,8 +10,12 @@ from pandas.compat._optional import import_optional_dependency from pandas.core.shared_docs import _shared_docs from pandas.io.excel import ExcelFile -from pandas.io.excel._base import BaseExcelReader -from pandas.util._decorators import doc +from pandas.io.excel._base import ( # type:ignore[attr-defined] # missing in pandas-stubs + BaseExcelReader, +) +from pandas.util._decorators import ( # type:ignore[attr-defined] # missing in pandas-stubs + doc, +) if TYPE_CHECKING: from pandas._typing import FilePath, ReadBuffer, StorageOptions @@ -123,8 +127,8 @@ def _convert_cell(value: _CellValueT) -> Scalar: return data -def pandas_monkeypatch(): - ExcelFile._engines = { +def pandas_monkeypatch() -> None: + ExcelFile._engines = { # type:ignore[attr-defined] # missing in pandas-stubs "calamine": CalamineExcelReader, - **ExcelFile._engines, + **ExcelFile._engines, # type:ignore[attr-defined] # missing in pandas-stubs }