Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openpyxl: add a few type annotations #9681

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions stubs/openpyxl/openpyxl/cell/cell.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import datetime
from _typeshed import Incomplete
from decimal import Decimal
from typing_extensions import TypeAlias

from openpyxl.styles.styleable import StyleableObject

Expand All @@ -19,6 +22,11 @@ TYPE_ERROR: str
TYPE_FORMULA_CACHE_STRING: str
VALID_TYPES: Incomplete

_Numeric: TypeAlias = int | float | Decimal | Incomplete # numpy types
_Time: TypeAlias = datetime.datetime | datetime.date | datetime.time | datetime.timedelta
_String: TypeAlias = str | bytes
_Value: TypeAlias = _Numeric | _Time | _String | bool | None

def get_type(t, value): ...
def get_time_format(t): ...

Expand All @@ -35,7 +43,7 @@ class Cell(StyleableObject):
style_array: Incomplete | None = ...,
) -> None: ...
@property
def coordinate(self): ...
def coordinate(self) -> str: ...
@property
def col_idx(self): ...
@property
Expand All @@ -47,9 +55,9 @@ class Cell(StyleableObject):
def check_string(self, value): ...
def check_error(self, value): ...
@property
def value(self): ...
def value(self) -> _Value: ...
@value.setter
def value(self, value) -> None: ...
def value(self, value: _Value) -> None: ...
@property
def internal_value(self): ...
@property
Expand Down
8 changes: 7 additions & 1 deletion stubs/openpyxl/openpyxl/reader/excel.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from _typeshed import Incomplete
from pathlib import Path
from typing import BinaryIO

from openpyxl.workbook.workbook import Workbook

SUPPORTED_FORMATS: Incomplete

Expand All @@ -23,4 +27,6 @@ class ExcelReader:
def read_worksheets(self) -> None: ...
def read(self) -> None: ...

def load_workbook(filename, read_only: bool = ..., keep_vba=..., data_only: bool = ..., keep_links: bool = ...): ...
def load_workbook(
filename: str | Path | BinaryIO, read_only: bool = ..., keep_vba: bool = ..., data_only: bool = ..., keep_links: bool = ...
) -> Workbook: ...
4 changes: 3 additions & 1 deletion stubs/openpyxl/openpyxl/workbook/workbook.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from _typeshed import Incomplete

from openpyxl.worksheet.worksheet import Worksheet

INTEGER_TYPES: Incomplete

class Workbook:
Expand Down Expand Up @@ -44,7 +46,7 @@ class Workbook:
def __contains__(self, key): ...
def index(self, worksheet): ...
def get_index(self, worksheet): ...
def __getitem__(self, key): ...
def __getitem__(self, key: str) -> Worksheet | Incomplete: ...
def __delitem__(self, key) -> None: ...
def __iter__(self): ...
def get_sheet_names(self): ...
Expand Down
10 changes: 5 additions & 5 deletions stubs/openpyxl/openpyxl/worksheet/cell_range.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ from openpyxl.descriptors import Strict
from openpyxl.descriptors.serialisable import Serialisable

class CellRange(Serialisable): # type: ignore[misc]
min_col: Incomplete
min_row: Incomplete
max_col: Incomplete
max_row: Incomplete
min_col: int
min_row: int
max_col: int
max_row: int
title: Incomplete
def __init__(
self,
Expand Down Expand Up @@ -60,7 +60,7 @@ class CellRange(Serialisable): # type: ignore[misc]
def right(self): ...

class MultiCellRange(Strict):
ranges: Incomplete
ranges: list[CellRange]
def __init__(self, ranges=...) -> None: ...
def __contains__(self, coord): ...
def add(self, coord) -> None: ...
Expand Down
8 changes: 6 additions & 2 deletions stubs/openpyxl/openpyxl/worksheet/worksheet.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from _typeshed import Incomplete
from collections.abc import Generator

from openpyxl.cell.cell import Cell, _Value as CellValue
from openpyxl.workbook.child import _WorkbookChild

from .cell_range import MultiCellRange

class Worksheet(_WorkbookChild):
mime_type: str
BREAK_NONE: int
Expand All @@ -25,6 +28,7 @@ class Worksheet(_WorkbookChild):
ORIENTATION_PORTRAIT: str
ORIENTATION_LANDSCAPE: str
def __init__(self, parent, title: Incomplete | None = ...) -> None: ...
merged_cells: MultiCellRange
@property
def sheet_view(self): ...
@property
Expand All @@ -43,8 +47,8 @@ class Worksheet(_WorkbookChild):
def freeze_panes(self): ...
@freeze_panes.setter
def freeze_panes(self, topLeftCell: Incomplete | None = ...) -> None: ...
def cell(self, row, column, value: Incomplete | None = ...): ...
def __getitem__(self, key): ...
def cell(self, row: int, column: int, value: CellValue | None = ...) -> Cell: ...
def __getitem__(self, key: slice | int | str) -> Cell | Generator[tuple[Cell, ...], None, None]: ...
def __setitem__(self, key, value) -> None: ...
def __iter__(self): ...
def __delitem__(self, key) -> None: ...
Expand Down