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

Type all @property in openpyxl #10787

Merged
merged 1 commit into from
Oct 4, 2023
Merged
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
20 changes: 20 additions & 0 deletions stubs/openpyxl/openpyxl/cell/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
from datetime import date, datetime, time, timedelta
from decimal import Decimal
from typing_extensions import TypeAlias

from openpyxl.cell.rich_text import CellRichText
from openpyxl.worksheet.formula import ArrayFormula, DataTableFormula

from .cell import Cell as Cell, MergedCell as MergedCell, WriteOnlyCell as WriteOnlyCell
from .read_only import ReadOnlyCell as ReadOnlyCell

_TimeTypes: TypeAlias = datetime | date | time | timedelta
_CellValue: TypeAlias = ( # noqa: Y047 # Used in other modules
# if numpy is installed also numpy bool and number types
bool
| float
| Decimal
| str
| CellRichText
| _TimeTypes
| DataTableFormula
| ArrayFormula
)
21 changes: 8 additions & 13 deletions stubs/openpyxl/openpyxl/cell/cell.pyi
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
from datetime import date, datetime, time, timedelta
from decimal import Decimal
from _typeshed import ReadableBuffer
from datetime import datetime
from re import Pattern
from typing import overload
from typing_extensions import Final, TypeAlias
from typing_extensions import Final

from openpyxl.cell.rich_text import CellRichText
from openpyxl.cell import _CellValue, _TimeTypes
from openpyxl.comments.comments import Comment
from openpyxl.styles.cell_style import StyleArray
from openpyxl.styles.styleable import StyleableObject
from openpyxl.worksheet.formula import ArrayFormula, DataTableFormula
from openpyxl.worksheet.hyperlink import Hyperlink
from openpyxl.worksheet.worksheet import Worksheet

_TimeTypes: TypeAlias = datetime | date | time | timedelta
_CellValue: TypeAlias = ( # if numpy is installed also numpy bool and number types
bool | float | Decimal | str | CellRichText | _TimeTypes | DataTableFormula | ArrayFormula
)

__docformat__: Final = "restructuredtext en"
TIME_TYPES: Final[tuple[type, ...]]
TIME_FORMATS: Final[dict[type[_TimeTypes], str]]
Expand Down Expand Up @@ -65,14 +59,14 @@ class Cell(StyleableObject):
@overload
def check_string(self, value: None) -> None: ...
@overload
def check_string(self, value: str | bytes) -> str: ...
def check_string(self, value: str | ReadableBuffer) -> str: ...
def check_error(self, value: object) -> str: ...
@property
def value(self) -> _CellValue: ...
def value(self) -> _CellValue | None: ...
@value.setter
def value(self, value: _CellValue | bytes | None) -> None: ...
@property
def internal_value(self) -> _CellValue: ...
def internal_value(self) -> _CellValue | None: ...
@property
def hyperlink(self) -> Hyperlink | None: ...
@hyperlink.setter
Expand All @@ -92,6 +86,7 @@ class MergedCell(StyleableObject):
row: int
column: int
def __init__(self, worksheet: Worksheet, row: int | None = None, column: int | None = None) -> None: ...
# Same as Cell.coordinate
@property
def coordinate(self) -> str: ...
value: str | float | int | datetime | None
Expand Down
41 changes: 26 additions & 15 deletions stubs/openpyxl/openpyxl/cell/read_only.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
from _typeshed import Incomplete
from typing_extensions import Final

from openpyxl.cell import _CellValue
from openpyxl.styles.alignment import Alignment
from openpyxl.styles.borders import Border
from openpyxl.styles.cell_style import StyleArray
from openpyxl.styles.fills import Fill
from openpyxl.styles.fonts import Font
from openpyxl.styles.protection import Protection

class ReadOnlyCell:
parent: Incomplete
row: Incomplete
Expand All @@ -9,35 +17,38 @@ class ReadOnlyCell:
def __init__(self, sheet, row, column, value, data_type: str = "n", style_id: int = 0) -> None: ...
def __eq__(self, other): ...
def __ne__(self, other): ...
# defined twice in the implementation
# Same as Cell.coordinate
# Defined twice in the implementation
@property
def coordinate(self): ...
def coordinate(self) -> str: ...
# Same as Cell.column_letter
@property
def column_letter(self): ...
def column_letter(self) -> str: ...
@property
def style_array(self): ...
def style_array(self) -> StyleArray: ...
@property
def has_style(self): ...
def has_style(self) -> bool: ...
@property
def number_format(self): ...
def number_format(self) -> str: ...
@property
def font(self): ...
def font(self) -> Font: ...
@property
def fill(self): ...
def fill(self) -> Fill: ...
@property
def border(self): ...
def border(self) -> Border: ...
@property
def alignment(self): ...
def alignment(self) -> Alignment: ...
@property
def protection(self): ...
def protection(self) -> Protection: ...
# Same as Cell.is_date
@property
def is_date(self): ...
def is_date(self) -> bool: ...
@property
def internal_value(self): ...
def internal_value(self) -> _CellValue | None: ...
@property
def value(self): ...
def value(self) -> _CellValue | None: ...
@value.setter
def value(self, value) -> None: ...
def value(self, value: None) -> None: ...

class EmptyCell:
value: Incomplete
Expand Down
2 changes: 1 addition & 1 deletion stubs/openpyxl/openpyxl/cell/text.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ class Text(Serialisable):
__elements__: ClassVar[tuple[str, ...]]
def __init__(self, t: object = None, r=(), rPh=(), phoneticPr: _PhoneticProperties | None = None) -> None: ...
@property
def content(self): ...
def content(self) -> str: ...
2 changes: 1 addition & 1 deletion stubs/openpyxl/openpyxl/chart/_chart.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ class ChartBase(Serialisable):
def add_data(self, data, from_rows: bool = False, titles_from_data: bool = False) -> None: ...
def append(self, value) -> None: ...
@property
def path(self): ...
def path(self) -> str: ...
6 changes: 3 additions & 3 deletions stubs/openpyxl/openpyxl/chart/reference.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class Reference(Strict):
def __len__(self) -> int: ...
def __eq__(self, other): ...
@property
def rows(self) -> Generator[Incomplete, None, None]: ...
def rows(self) -> Generator[Reference, None, None]: ...
@property
def cols(self) -> Generator[Incomplete, None, None]: ...
def cols(self) -> Generator[Reference, None, None]: ...
def pop(self): ...
@property
def sheetname(self): ...
def sheetname(self) -> str: ...
7 changes: 4 additions & 3 deletions stubs/openpyxl/openpyxl/comments/comment_sheet.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ from typing_extensions import Literal, TypeAlias

from openpyxl.cell.text import Text
from openpyxl.comments.author import AuthorList
from openpyxl.comments.comments import Comment
from openpyxl.descriptors.base import Bool, Integer, Set, String, Typed, _ConvertibleToBool, _ConvertibleToInt
from openpyxl.descriptors.excel import ExtensionList
from openpyxl.descriptors.serialisable import Serialisable
Expand Down Expand Up @@ -101,7 +102,7 @@ class CommentRecord(Serialisable):
@classmethod
def from_cell(cls, cell): ...
@property
def content(self): ...
def content(self) -> str: ...

class CommentSheet(Serialisable):
tagname: ClassVar[str]
Expand All @@ -113,9 +114,9 @@ class CommentSheet(Serialisable):
def __init__(self, authors: AuthorList, commentList: Incomplete | None = None, extLst: Unused = None) -> None: ...
def to_tree(self): ...
@property
def comments(self) -> Generator[Incomplete, None, None]: ...
def comments(self) -> Generator[tuple[str, Comment], None, None]: ...
@classmethod
def from_comments(cls, comments): ...
def write_shapes(self, vml: Incomplete | None = None): ...
@property
def path(self): ...
def path(self) -> str: ...
7 changes: 4 additions & 3 deletions stubs/openpyxl/openpyxl/comments/comments.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from _typeshed import Incomplete
from typing import Any

class Comment:
content: Incomplete
Expand All @@ -7,12 +8,12 @@ class Comment:
width: Incomplete
def __init__(self, text, author, height: int = 79, width: int = 144) -> None: ...
@property
def parent(self): ...
def parent(self) -> Any: ... # AnyOf[Cell, MergedCell, ReadOnlyCell]
def __eq__(self, other): ...
def __copy__(self): ...
def bind(self, cell) -> None: ...
def unbind(self) -> None: ...
@property
def text(self): ...
def text(self) -> str: ...
@text.setter
def text(self, value) -> None: ...
def text(self, value: str) -> None: ...
12 changes: 7 additions & 5 deletions stubs/openpyxl/openpyxl/drawing/drawing.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from _typeshed import Incomplete

from .spreadsheet_drawing import AbsoluteAnchor, OneCellAnchor

class Drawing:
count: int
name: str
Expand All @@ -14,13 +16,13 @@ class Drawing:
anchorrow: int
def __init__(self) -> None: ...
@property
def width(self): ...
def width(self) -> int: ...
@width.setter
def width(self, w) -> None: ...
def width(self, w: int) -> None: ...
@property
def height(self): ...
def height(self) -> int: ...
@height.setter
def height(self, h) -> None: ...
def height(self, h: int) -> None: ...
def set_dimension(self, w: int = 0, h: int = 0) -> None: ...
@property
def anchor(self): ...
def anchor(self) -> AbsoluteAnchor | OneCellAnchor: ...
2 changes: 1 addition & 1 deletion stubs/openpyxl/openpyxl/drawing/image.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class Image:
format: Incomplete
def __init__(self, img) -> None: ...
@property
def path(self): ...
def path(self) -> str: ...
2 changes: 1 addition & 1 deletion stubs/openpyxl/openpyxl/drawing/spreadsheet_drawing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ class SpreadsheetDrawing(Serialisable):
def __hash__(self) -> int: ...
def __bool__(self) -> bool: ...
@property
def path(self): ...
def path(self) -> str: ...
15 changes: 11 additions & 4 deletions stubs/openpyxl/openpyxl/formula/tokenizer.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from _typeshed import Incomplete
from re import Pattern
from typing_extensions import Final
from typing_extensions import Final, Literal, TypeAlias

_TokenTypesNotOperand: TypeAlias = Literal[
"LITERAL", "FUNC", "ARRAY", "PAREN", "SEP", "OPERATOR-PREFIX", "OPERATOR-INFIX", "OPERATOR-POSTFIX", "WHITE-SPACE"
]
_TokenTypes: TypeAlias = Literal["OPERAND", _TokenTypesNotOperand]
_TokenOperandSubtypes: TypeAlias = Literal["TEXT", "NUMBER", "LOGICAL", "ERROR", "RANGE"]
_TokenSubtypes: TypeAlias = Literal["", _TokenOperandSubtypes, "OPEN", "CLOSE", "ARG", "ROW"]

class TokenizerError(Exception): ...

Expand Down Expand Up @@ -33,9 +40,9 @@ class Token:
OP_POST: Final = "OPERATOR-POSTFIX"
WSPACE: Final = "WHITE-SPACE"
value: Incomplete
type: Incomplete
subtype: Incomplete
def __init__(self, value, type_, subtype: str = "") -> None: ...
type: _TokenTypes
subtype: _TokenSubtypes
def __init__(self, value, type_: _TokenTypes, subtype: _TokenSubtypes = "") -> None: ...
TEXT: Final = "TEXT"
NUMBER: Final = "NUMBER"
LOGICAL: Final = "LOGICAL"
Expand Down
8 changes: 5 additions & 3 deletions stubs/openpyxl/openpyxl/packaging/interface.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from abc import ABC, ABCMeta, abstractmethod
from abc import ABC, abstractmethod

class ISerialisableFile(ABC, metaclass=ABCMeta):
# This interface is unused. Nothing implements `id` as property either.
# IDs can be ints, strings, None, or a Descriptor returning those throughout the codebase.
class ISerialisableFile(ABC):
@property
@abstractmethod
def id(self): ...
def id(self) -> str | int | None: ...
4 changes: 2 additions & 2 deletions stubs/openpyxl/openpyxl/packaging/manifest.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class Manifest(Serialisable):
__elements__: ClassVar[tuple[str, ...]]
def __init__(self, Default=(), Override=()) -> None: ...
@property
def filenames(self): ...
def filenames(self) -> list[str]: ...
@property
def extensions(self): ...
def extensions(self) -> list[tuple[str, str]]: ...
def to_tree(self): ...
def __contains__(self, content_type): ...
def find(self, content_type): ...
Expand Down
2 changes: 1 addition & 1 deletion stubs/openpyxl/openpyxl/packaging/workbook.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ class WorkbookPackage(Serialisable):
) -> None: ...
def to_tree(self): ...
@property
def active(self): ...
def active(self) -> int: ...
10 changes: 5 additions & 5 deletions stubs/openpyxl/openpyxl/pivot/cache.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class ServerFormatList(Serialisable):
__attrs__: ClassVar[tuple[str, ...]]
def __init__(self, count: Incomplete | None = None, serverFormat: Incomplete | None = None) -> None: ...
@property
def count(self): ...
def count(self) -> int: ...

class Query(Serialisable):
tagname: ClassVar[str]
Expand Down Expand Up @@ -384,7 +384,7 @@ class GroupItems(Serialisable):
__attrs__: ClassVar[tuple[str, ...]]
def __init__(self, count: Incomplete | None = None, m=(), n=(), b=(), e=(), s=(), d=()) -> None: ...
@property
def count(self): ...
def count(self) -> int: ...

class DiscretePr(Serialisable):
tagname: ClassVar[str]
Expand Down Expand Up @@ -475,7 +475,7 @@ class SharedItems(Serialisable):
longText: _ConvertibleToBool | None = None,
) -> None: ...
@property
def count(self): ...
def count(self) -> int: ...

class CacheField(Serialisable):
tagname: ClassVar[str]
Expand Down Expand Up @@ -585,7 +585,7 @@ class Page(Serialisable):
__elements__: ClassVar[tuple[str, ...]]
def __init__(self, count: Incomplete | None = None, pageItem: Incomplete | None = None) -> None: ...
@property
def count(self): ...
def count(self) -> int: ...

class Consolidation(Serialisable):
tagname: ClassVar[str]
Expand Down Expand Up @@ -723,4 +723,4 @@ class CacheDefinition(Serialisable):
) -> None: ...
def to_tree(self): ...
@property
def path(self): ...
def path(self) -> str: ...
4 changes: 2 additions & 2 deletions stubs/openpyxl/openpyxl/pivot/record.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class RecordList(Serialisable):
__attrs__: ClassVar[tuple[str, ...]]
def __init__(self, count: Unused = None, r=(), extLst: ExtensionList | None = None) -> None: ...
@property
def count(self): ...
def count(self) -> int: ...
def to_tree(self): ...
@property
def path(self): ...
def path(self) -> str: ...
Loading