Skip to content

Commit

Permalink
fix(typing): apply mypy.stubtest
Browse files Browse the repository at this point in the history
  • Loading branch information
dimastbk committed Jan 6, 2024
1 parent a0b5b30 commit 47e0885
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions python/python_calamine/_python_calamine.pyi
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
from __future__ import annotations

import datetime
import enum
from datetime import date, datetime, time, timedelta
from os import PathLike
from typing import Protocol
import os
import typing

ValueT = int | float | str | bool | time | date | datetime | timedelta

class ReadBuffer(Protocol):
@typing.type_check_only
class ReadBuffer(typing.Protocol):
def seek(self, __offset: int, __whence: int = ...) -> int: ...
def read(self, __size: int = ...) -> bytes | None: ...

@typing.final
class SheetTypeEnum(enum.Enum):
WorkSheet = ...
DialogSheet = ...
MacroSheet = ...
ChartSheet = ...
VBA = ...
Vba = ...

@typing.final
class SheetVisibleEnum(enum.Enum):
Visible = ...
Hidden = ...
VeryHidden = ...

@typing.final
class SheetMetadata:
name: str
typ: SheetTypeEnum
Expand All @@ -32,6 +34,7 @@ class SheetMetadata:
self, name: str, typ: SheetTypeEnum, visible: SheetVisibleEnum
) -> None: ...

@typing.final
class CalamineSheet:
name: str
@property
Expand All @@ -48,7 +51,18 @@ class CalamineSheet:
def end(self) -> tuple[int, int] | None: ...
def to_python(
self, skip_empty_area: bool = True, nrows: int | None = None
) -> list[list[ValueT]]:
) -> list[
list[
int
| float
| str
| bool
| datetime.time
| datetime.date
| datetime.datetime
| datetime.timedelta
]
]:
"""Retunrning data from sheet as list of lists.
Parameters
Expand All @@ -58,13 +72,14 @@ class CalamineSheet:
For suppress this behaviour, set `skip_empty_area` to `False`.
"""

@typing.final
class CalamineWorkbook:
path: str | None
sheet_names: list[str]
sheets_metadata: list[SheetMetadata]
@classmethod
def from_object(
cls, path_or_filelike: str | PathLike | ReadBuffer
cls, path_or_filelike: str | os.PathLike | ReadBuffer
) -> "CalamineWorkbook":
"""Determining type of pyobject and reading from it.
Expand All @@ -76,7 +91,7 @@ class CalamineWorkbook:
- IO (must imlpement read/seek methods).
"""
@classmethod
def from_path(cls, path: str | PathLike) -> "CalamineWorkbook":
def from_path(cls, path: str | os.PathLike) -> "CalamineWorkbook":
"""Reading file from path.
Parameters
Expand All @@ -96,7 +111,7 @@ class CalamineWorkbook:
class CalamineError(Exception): ...

def load_workbook(
path_or_filelike: str | PathLike | ReadBuffer,
path_or_filelike: str | os.PathLike | ReadBuffer,
) -> CalamineWorkbook:
"""Determining type of pyobject and reading from it.
Expand Down

0 comments on commit 47e0885

Please sign in to comment.