Skip to content

Commit

Permalink
openpyxl: Make common alias for visibility literal string union (#10562)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored Aug 15, 2023
1 parent af36a15 commit 6c7be1e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
3 changes: 3 additions & 0 deletions stubs/openpyxl/openpyxl/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Protocol
from typing_extensions import Literal, TypeAlias

from openpyxl.compat.numbers import NUMPY as NUMPY
from openpyxl.reader.excel import load_workbook as load_workbook
Expand All @@ -18,5 +19,7 @@ DEBUG: bool
open = load_workbook

# Utility types reused elsewhere
_VisibilityType: TypeAlias = Literal["visible", "hidden", "veryHidden"] # noqa: Y047

class _Decodable(Protocol): # noqa: Y046
def decode(self, __encoding: str) -> str: ...
10 changes: 4 additions & 6 deletions stubs/openpyxl/openpyxl/chartsheet/chartsheet.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from _typeshed import Incomplete, Unused
from typing import ClassVar
from typing_extensions import Literal, TypeAlias
from typing_extensions import Literal

from openpyxl import _Decodable
from openpyxl import _Decodable, _VisibilityType
from openpyxl.chartsheet.custom import CustomChartsheetViews
from openpyxl.chartsheet.properties import ChartsheetProperties
from openpyxl.chartsheet.protection import ChartsheetProtection
Expand All @@ -17,8 +17,6 @@ from openpyxl.worksheet.drawing import Drawing
from openpyxl.worksheet.header_footer import HeaderFooter as _HeaderFooter
from openpyxl.worksheet.page import PageMargins, PrintPageSetup

_ChartsheetSheetState: TypeAlias = Literal["visible", "hidden", "veryHidden"]

class Chartsheet(_WorkbookChild, Serialisable):
tagname: ClassVar[str]
mime_type: str
Expand All @@ -33,7 +31,7 @@ class Chartsheet(_WorkbookChild, Serialisable):
picture: Typed[SheetBackgroundPicture, Literal[True]]
webPublishItems: Typed[WebPublishItems, Literal[True]]
extLst: Typed[ExtensionList, Literal[True]]
sheet_state: Set[_ChartsheetSheetState]
sheet_state: Set[_VisibilityType]
headerFooter: Typed[_HeaderFooter, Literal[False]]
HeaderFooter: Alias
__elements__: ClassVar[tuple[str, ...]]
Expand All @@ -54,7 +52,7 @@ class Chartsheet(_WorkbookChild, Serialisable):
extLst: Unused = None,
parent: Incomplete | None = None,
title: str | _Decodable | None = "",
sheet_state: _ChartsheetSheetState = "visible",
sheet_state: _VisibilityType = "visible",
) -> None: ...
def add_chart(self, chart) -> None: ...
def to_tree(self): ...
11 changes: 5 additions & 6 deletions stubs/openpyxl/openpyxl/chartsheet/custom.pyi
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
from _typeshed import Incomplete
from typing import ClassVar, overload
from typing_extensions import Literal, TypeAlias
from typing_extensions import Literal

from openpyxl import _VisibilityType
from openpyxl.descriptors.base import Bool, Integer, Set, Typed, _ConvertibleToBool, _ConvertibleToInt
from openpyxl.descriptors.serialisable import Serialisable
from openpyxl.worksheet.header_footer import HeaderFooter
from openpyxl.worksheet.page import PageMargins, PrintPageSetup

_CustomChartsheetViewState: TypeAlias = Literal["visible", "hidden", "veryHidden"]

class CustomChartsheetView(Serialisable):
tagname: ClassVar[str]
guid: Incomplete
scale: Integer[Literal[False]]
state: Set[_CustomChartsheetViewState]
state: Set[_VisibilityType]
zoomToFit: Bool[Literal[True]]
pageMargins: Typed[PageMargins, Literal[True]]
pageSetup: Typed[PrintPageSetup, Literal[True]]
Expand All @@ -25,7 +24,7 @@ class CustomChartsheetView(Serialisable):
guid: Incomplete | None = None,
*,
scale: _ConvertibleToInt,
state: _CustomChartsheetViewState = "visible",
state: _VisibilityType = "visible",
zoomToFit: _ConvertibleToBool | None = None,
pageMargins: PageMargins | None = None,
pageSetup: PrintPageSetup | None = None,
Expand All @@ -36,7 +35,7 @@ class CustomChartsheetView(Serialisable):
self,
guid: Incomplete | None,
scale: _ConvertibleToInt,
state: _CustomChartsheetViewState = "visible",
state: _VisibilityType = "visible",
zoomToFit: _ConvertibleToBool | None = None,
pageMargins: PageMargins | None = None,
pageSetup: PrintPageSetup | None = None,
Expand Down
6 changes: 3 additions & 3 deletions stubs/openpyxl/openpyxl/packaging/workbook.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ from _typeshed import Incomplete, Unused
from typing import ClassVar
from typing_extensions import Literal, TypeAlias

from openpyxl import _VisibilityType
from openpyxl.descriptors.base import Alias, Bool, Integer, NoneSet, String, Typed, _ConvertibleToBool, _ConvertibleToInt
from openpyxl.descriptors.excel import ExtensionList
from openpyxl.descriptors.nested import NestedString
Expand All @@ -13,7 +14,6 @@ from openpyxl.workbook.protection import FileSharing, WorkbookProtection
from openpyxl.workbook.smart_tags import SmartTagList, SmartTagProperties
from openpyxl.workbook.web import WebPublishing, WebPublishObjectList

_ChildSheetState: TypeAlias = Literal["visible", "hidden", "veryHidden"]
_WorkbookPackageConformance: TypeAlias = Literal["strict", "transitional"]

class FileRecoveryProperties(Serialisable):
Expand All @@ -34,13 +34,13 @@ class ChildSheet(Serialisable):
tagname: ClassVar[str]
name: String[Literal[False]]
sheetId: Integer[Literal[False]]
state: NoneSet[_ChildSheetState]
state: NoneSet[_VisibilityType]
id: Incomplete
def __init__(
self,
name: str,
sheetId: _ConvertibleToInt,
state: _ChildSheetState | Literal["none"] | None = "visible",
state: _VisibilityType | Literal["none"] | None = "visible",
id: Incomplete | None = None,
) -> None: ...

Expand Down
6 changes: 3 additions & 3 deletions stubs/openpyxl/openpyxl/workbook/views.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ from _typeshed import Incomplete, Unused
from typing import ClassVar, overload
from typing_extensions import Literal, TypeAlias

from openpyxl import _VisibilityType
from openpyxl.descriptors.base import Bool, Integer, NoneSet, String, Typed, _ConvertibleToBool, _ConvertibleToInt
from openpyxl.descriptors.excel import ExtensionList
from openpyxl.descriptors.serialisable import Serialisable

_BookViewVilibility: TypeAlias = Literal["visible", "hidden", "veryHidden"]
_CustomWorkbookViewShowComments: TypeAlias = Literal["commNone", "commIndicator", "commIndAndComment"]
_CustomWorkbookViewShowObjects: TypeAlias = Literal["all", "placeholders"]

class BookView(Serialisable):
tagname: ClassVar[str]
visibility: NoneSet[_BookViewVilibility]
visibility: NoneSet[_VisibilityType]
minimized: Bool[Literal[True]]
showHorizontalScroll: Bool[Literal[True]]
showVerticalScroll: Bool[Literal[True]]
Expand All @@ -29,7 +29,7 @@ class BookView(Serialisable):
__elements__: ClassVar[tuple[str, ...]]
def __init__(
self,
visibility: _BookViewVilibility | Literal["none"] | None = "visible",
visibility: _VisibilityType | Literal["none"] | None = "visible",
minimized: _ConvertibleToBool | None = False,
showHorizontalScroll: _ConvertibleToBool | None = True,
showVerticalScroll: _ConvertibleToBool | None = True,
Expand Down
3 changes: 2 additions & 1 deletion stubs/openpyxl/openpyxl/worksheet/_read_only.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from _typeshed import Incomplete

from openpyxl import _VisibilityType
from openpyxl.worksheet.worksheet import Worksheet

def read_dimension(source): ...
Expand All @@ -15,7 +16,7 @@ class ReadOnlyWorksheet:
__iter__ = Worksheet.__iter__
parent: Incomplete
title: str
sheet_state: str
sheet_state: _VisibilityType
def __init__(self, parent_workbook, title: str, worksheet_path, shared_strings) -> None: ...
def calculate_dimension(self, force: bool = False): ...
def reset_dimensions(self) -> None: ...
Expand Down
4 changes: 2 additions & 2 deletions stubs/openpyxl/openpyxl/worksheet/worksheet.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from datetime import datetime
from typing import Any, overload
from typing_extensions import Final, Literal

from openpyxl import _Decodable
from openpyxl import _Decodable, _VisibilityType
from openpyxl.cell.cell import Cell, _CellValue
from openpyxl.formatting.formatting import ConditionalFormattingList
from openpyxl.workbook.child import _WorkbookChild
Expand Down Expand Up @@ -53,7 +53,7 @@ class Worksheet(_WorkbookChild):
col_breaks: ColBreak
merged_cells: MultiCellRange
data_validations: DataValidationList
sheet_state: Literal["visible", "hidden", "veryHidden"]
sheet_state: _VisibilityType
page_setup: PrintPageSetup
print_options: PrintOptions
page_margins: PageMargins
Expand Down

0 comments on commit 6c7be1e

Please sign in to comment.