From 381fc572a8ae82ecc4359d3f805770ed2e72f12c Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 22 Sep 2023 22:45:08 -0400 Subject: [PATCH] Complete openpyxl metaclasses (#10736) --- stubs/openpyxl/openpyxl/compat/singleton.pyi | 16 +++++++--- .../openpyxl/descriptors/__init__.pyi | 6 ++-- stubs/openpyxl/openpyxl/descriptors/slots.pyi | 4 ++- stubs/openpyxl/openpyxl/styles/cell_style.pyi | 29 ++++++++++--------- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/stubs/openpyxl/openpyxl/compat/singleton.pyi b/stubs/openpyxl/openpyxl/compat/singleton.pyi index 65403a663432..859a30110c22 100644 --- a/stubs/openpyxl/openpyxl/compat/singleton.pyi +++ b/stubs/openpyxl/openpyxl/compat/singleton.pyi @@ -1,7 +1,15 @@ +from typing import Any, overload + class Singleton(type): - def __init__(self, *args, **kw) -> None: ... - def __call__(self, *args, **kw): ... + @overload + def __init__(self, __o: object) -> None: ... + @overload + def __init__(self, __name: str, __bases: tuple[type, ...], __dict: dict[str, Any], **kwds: Any) -> None: ... + def __call__(self, *args: Any, **kwds: Any) -> Any: ... class Cached(type): - def __init__(self, *args, **kw) -> None: ... - def __call__(self, *args): ... + @overload + def __init__(self, __o: object) -> None: ... + @overload + def __init__(self, __name: str, __bases: tuple[type, ...], __dict: dict[str, Any], **kwds: Any) -> None: ... + def __call__(self, *args: Any) -> Any: ... diff --git a/stubs/openpyxl/openpyxl/descriptors/__init__.pyi b/stubs/openpyxl/openpyxl/descriptors/__init__.pyi index 5817c55b8213..18097e820254 100644 --- a/stubs/openpyxl/openpyxl/descriptors/__init__.pyi +++ b/stubs/openpyxl/openpyxl/descriptors/__init__.pyi @@ -1,10 +1,12 @@ +from _typeshed import Incomplete, Self + from .base import * from .sequence import Sequence as Sequence class MetaStrict(type): - def __new__(cls, clsname, bases, methods): ... + def __new__(cls: type[Self], clsname: str, bases: tuple[type, ...], methods: dict[str, Descriptor[Incomplete]]) -> Self: ... class MetaSerialisable(type): - def __new__(cls, clsname, bases, methods): ... + def __new__(cls: type[Self], clsname: str, bases: tuple[type, ...], methods: dict[str, Descriptor[Incomplete]]) -> Self: ... class Strict(metaclass=MetaStrict): ... diff --git a/stubs/openpyxl/openpyxl/descriptors/slots.pyi b/stubs/openpyxl/openpyxl/descriptors/slots.pyi index ebfc3090e22c..f74e59307e6e 100644 --- a/stubs/openpyxl/openpyxl/descriptors/slots.pyi +++ b/stubs/openpyxl/openpyxl/descriptors/slots.pyi @@ -1,2 +1,4 @@ +from _typeshed import Incomplete, Self + class AutoSlotProperties(type): - def __new__(mcl, classname, bases, dictionary): ... + def __new__(mcl: type[Self], classname: str, bases: tuple[type, ...], dictionary: dict[str, Incomplete]) -> Self: ... diff --git a/stubs/openpyxl/openpyxl/styles/cell_style.pyi b/stubs/openpyxl/openpyxl/styles/cell_style.pyi index 22362cf54be5..419464400e69 100644 --- a/stubs/openpyxl/openpyxl/styles/cell_style.pyi +++ b/stubs/openpyxl/openpyxl/styles/cell_style.pyi @@ -1,7 +1,8 @@ from _typeshed import Incomplete, Unused from array import array +from collections.abc import Iterable from typing import ClassVar -from typing_extensions import Literal +from typing_extensions import Literal, Self from openpyxl.descriptors import Strict from openpyxl.descriptors.base import Bool, Integer, Typed, _ConvertibleToBool, _ConvertibleToInt @@ -16,21 +17,21 @@ class ArrayDescriptor: def __get__(self, instance: Serialisable | Strict, cls: Unused): ... def __set__(self, instance: Serialisable | Strict, value) -> None: ... -class StyleArray(array[Incomplete]): +class StyleArray(array[int]): tagname: ClassVar[str] - fontId: Incomplete - fillId: Incomplete - borderId: Incomplete - numFmtId: Incomplete - protectionId: Incomplete - alignmentId: Incomplete - pivotButton: Incomplete - quotePrefix: Incomplete - xfId: Incomplete - def __new__(cls, args=[0, 0, 0, 0, 0, 0, 0, 0, 0]): ... + fontId: ArrayDescriptor + fillId: ArrayDescriptor + borderId: ArrayDescriptor + numFmtId: ArrayDescriptor + protectionId: ArrayDescriptor + alignmentId: ArrayDescriptor + pivotButton: ArrayDescriptor + quotePrefix: ArrayDescriptor + xfId: ArrayDescriptor + def __new__(cls, args: bytes | bytearray | Iterable[int] = [0, 0, 0, 0, 0, 0, 0, 0, 0]) -> Self: ... def __hash__(self) -> int: ... - def __copy__(self): ... - def __deepcopy__(self, memo): ... + def __copy__(self) -> StyleArray: ... + def __deepcopy__(self, memo: Unused) -> StyleArray: ... class CellStyle(Serialisable): tagname: ClassVar[str]