Mark stub-only private symbols as @type_check_only in third-party stubs (#14545)

This commit is contained in:
Brian Schubert
2025-08-08 11:29:48 +02:00
committed by GitHub
parent a358dc24e8
commit 81c8fcb2e6
131 changed files with 334 additions and 147 deletions
+2 -1
View File
@@ -1,5 +1,5 @@
from _typeshed import StrPath, SupportsRead, SupportsWrite
from typing import IO, Literal, Protocol
from typing import IO, Literal, Protocol, type_check_only
from typing_extensions import TypeAlias
from openpyxl.compat.numbers import NUMPY as NUMPY
@@ -27,5 +27,6 @@ _VisibilityType: TypeAlias = Literal["visible", "hidden", "veryHidden"] # noqa:
_ZipFileFileProtocol: TypeAlias = StrPath | IO[bytes] | SupportsRead[bytes] # noqa: Y047
_ZipFileFileWriteProtocol: TypeAlias = StrPath | IO[bytes] | SupportsWrite[bytes] # noqa: Y047
@type_check_only
class _Decodable(Protocol): # noqa: Y046
def decode(self, encoding: str, /) -> str: ...
@@ -1,6 +1,6 @@
from _typeshed import Incomplete, Unused
from collections.abc import Generator, Iterable, Sized
from typing import Any, Protocol, TypeVar
from typing import Any, Protocol, TypeVar, type_check_only
from typing_extensions import Self
from openpyxl.descriptors import Strict
@@ -13,10 +13,12 @@ from .base import Alias, Descriptor
_T = TypeVar("_T")
_ContainerT = TypeVar("_ContainerT")
@type_check_only
class _SupportsFromTree(Protocol):
@classmethod
def from_tree(cls, node: _SerialisableTreeElement) -> Any: ...
@type_check_only
class _SupportsToTree(Protocol):
def to_tree(self) -> Element: ...
@@ -47,6 +49,7 @@ class ValueSequence(Sequence[_ContainerT]):
) -> Generator[Element, None, None]: ...
def from_tree(self, node: _HasGet[_T]) -> _T: ...
@type_check_only
class _NestedSequenceToTreeObj(Sized, Iterable[_SupportsToTree], Protocol): ...
# See `Sequence` for the meaning of `_ContainerT`.
@@ -1,6 +1,6 @@
from _typeshed import ConvertibleToInt, Incomplete, SupportsIter
from collections.abc import Iterator
from typing import Any, ClassVar, Final, Protocol
from typing import Any, ClassVar, Final, Protocol, type_check_only
from typing_extensions import Self
from openpyxl.descriptors import MetaSerialisable
@@ -9,7 +9,10 @@ from openpyxl.xml.functions import Element
from ..xml._functions_overloads import _HasAttrib, _HasGet, _HasTagAndGet, _HasText, _SupportsFindChartLines
# For any override directly re-using Serialisable.from_tree
@type_check_only
class _ChildSerialisableTreeElement(_HasAttrib, _HasText, SupportsIter[Incomplete], Protocol): ...
@type_check_only
class _SerialisableTreeElement(_HasGet[object], _SupportsFindChartLines, _ChildSerialisableTreeElement, Protocol): ...
KEYWORDS: Final[frozenset[str]]
@@ -1,6 +1,6 @@
from _typeshed import Incomplete, ReadableBuffer, StrPath, Unused
from collections.abc import Generator, Iterable
from typing import Protocol
from typing import Protocol, type_check_only
from typing_extensions import TypeAlias
from openpyxl.cell import _CellOrMergedCell
@@ -8,6 +8,7 @@ from openpyxl.worksheet._write_only import WriteOnlyWorksheet
from openpyxl.worksheet.worksheet import Worksheet
# WorksheetWriter.read has an explicit BytesIO branch. Let's make sure this protocol is viable for BytesIO too.
@type_check_only
class _SupportsCloseAndWrite(Protocol):
def write(self, buffer: ReadableBuffer, /) -> Unused: ...
def close(self) -> Unused: ...
@@ -1,5 +1,5 @@
from _typeshed import ConvertibleToInt, Incomplete
from typing import ClassVar, Literal, Protocol
from typing import ClassVar, Literal, Protocol, type_check_only
from typing_extensions import TypeAlias
from openpyxl.descriptors.base import (
@@ -36,6 +36,7 @@ _DataValidationOperator: TypeAlias = Literal[
"between", "notBetween", "equal", "notEqual", "lessThan", "lessThanOrEqual", "greaterThan", "greaterThanOrEqual"
]
@type_check_only
class _HasCoordinate(Protocol):
coordinate: str | CellRange