Skip to content

Commit

Permalink
Merge pull request #47 from dimastbk/issue46
Browse files Browse the repository at this point in the history
fix ReadBuffer type, add mypy to pre-commit
  • Loading branch information
dimastbk committed Jan 4, 2024
2 parents bb1e94d + 46d4657 commit b0bedb8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
17 changes: 12 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,30 +10,37 @@ 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)
- id: isort
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
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions python/python_calamine/_python_calamine.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...
Expand Down
14 changes: 9 additions & 5 deletions python/python_calamine/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit b0bedb8

Please sign in to comment.