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
@@ -1,4 +1,5 @@
from _typeshed import Incomplete
from typing import type_check_only
from reportlab.graphics.shapes import Rect
from reportlab.graphics.widgetbase import Widget
@@ -7,11 +8,13 @@ from reportlab.platypus.flowables import Flowable
__all__ = ["QrCodeWidget"]
@type_check_only
class _isLevel(Validator):
def test(self, x): ...
isLevel: _isLevel
@type_check_only
class _isUnicodeOrQRList(Validator):
def test(self, x): ...
def normalize(self, x): ...
+11 -1
View File
@@ -1,7 +1,7 @@
from _typeshed import Incomplete, SupportsItems
from abc import abstractmethod
from collections.abc import Iterable, Sequence
from typing import Any, Final, Literal, NoReturn, TypedDict
from typing import Any, Final, Literal, NoReturn, TypedDict, type_check_only
from typing_extensions import Self, TypeAlias, Unpack
from reportlab.lib.colors import Color
@@ -25,6 +25,7 @@ _PathOp: TypeAlias = (
# NOTE: These are derived from _attrMap and can optionally be
# verified at runtime
@type_check_only
class _GroupKwArgs(TypedDict, total=False):
transform: tuple[float, float, float, float, float, float] | list[float] | list[int]
# NOTE: This should be used with care, since it will replace elements
@@ -35,6 +36,7 @@ class _GroupKwArgs(TypedDict, total=False):
fillOverprint: _BoolLike
overprintMask: _BoolLike
@type_check_only
class _DrawingKwArgs(_GroupKwArgs, total=False):
# TODO: Restrict to supported formats?
formats: list[str] | tuple[str, ...]
@@ -50,6 +52,7 @@ class _DrawingKwArgs(_GroupKwArgs, total=False):
initialFontName: str | None
initialFontSize: float | None
@type_check_only
class _LineShapeKwArgs(TypedDict, total=False):
strokeColor: Color | None
strokeWidth: float
@@ -61,11 +64,13 @@ class _LineShapeKwArgs(TypedDict, total=False):
strokeOverprint: _BoolLike
overprintMask: _BoolLike
@type_check_only
class _PathKwArgs(_LineShapeKwArgs, total=False):
fillColor: Color | None
fillOpacity: float
fillOverprint: _BoolLike
@type_check_only
class _AllPathKwArgs(_PathKwArgs, total=False):
points: list[float] | None
operators: list[float] | None
@@ -73,17 +78,21 @@ class _AllPathKwArgs(_PathKwArgs, total=False):
autoclose: Literal["svg", "pdf"] | None
fillMode: Literal[0, 1]
@type_check_only
class _SolidShapeKwArgs(_PathKwArgs, total=False):
fillMode: Literal[0, 1]
@type_check_only
class _DefinePathKwArgs(_SolidShapeKwArgs, total=False):
autoclose: Literal["svg", "pdf"] | None
bbox: tuple[float, float, float, float] | None
@type_check_only
class _WedgeKwArgs(_SolidShapeKwArgs, total=False):
radius1: float | None
yradius1: float | None
@type_check_only
class _StringKwArgs(TypedDict, total=False):
fontName: str
fontSize: float
@@ -161,6 +170,7 @@ class Drawing(Group, Flowable):
class _DrawingEditorMixin: ...
@type_check_only
class _isStrokeDashArray(Validator):
def test(self, x): ...
+3 -2
View File
@@ -1,5 +1,5 @@
from collections.abc import Iterable, Iterator
from typing import Final, Literal, TypeVar, overload
from typing import Final, Literal, TypeVar, overload, type_check_only
from typing_extensions import Self, TypeAlias
_ColorT = TypeVar("_ColorT", bound=Color)
@@ -288,7 +288,7 @@ def describe(aColor: Color, mode: Literal[1]) -> str: ...
def describe(aColor: Color, mode: Literal[2]) -> tuple[str, float]: ...
def hue2rgb(m1: float, m2: float, h: float) -> float: ...
def hsl2rgb(h: float, s: float, l: float) -> tuple[float, float, float]: ...
@type_check_only
class _cssParse:
def pcVal(self, v: str) -> float: ...
def rgbPcVal(self, v: str) -> float: ...
@@ -300,6 +300,7 @@ class _cssParse:
cssParse: _cssParse
@type_check_only
class _toColor:
extraColorsNS: dict[str, Color]
def __init__(self) -> None: ...
@@ -1,8 +1,10 @@
from _typeshed import Incomplete
from typing import type_check_only
RequirePyRXP: int
simpleparse: int
@type_check_only
class _smartDecode:
@staticmethod
def __call__(s): ...
+2 -1
View File
@@ -4,7 +4,7 @@ from _typeshed import Incomplete, SupportsItems
from collections.abc import Generator, Iterable
from os import PathLike
from types import TracebackType
from typing import AnyStr, Final, Literal, TypeVar, overload
from typing import AnyStr, Final, Literal, TypeVar, overload, type_check_only
from reportlab.lib.rltempfile import get_rl_tempdir as get_rl_tempdir, get_rl_tempfile as get_rl_tempfile
@@ -19,6 +19,7 @@ _VT = TypeVar("_VT")
__version__: Final[str]
@type_check_only
class _UNSET_:
@staticmethod
def __bool__() -> Literal[False]: ...
@@ -1,7 +1,7 @@
from _typeshed import Incomplete
from abc import abstractmethod
from collections.abc import Callable
from typing import IO, Any, Literal, Protocol
from typing import IO, Any, Literal, Protocol, type_check_only
from typing_extensions import Self, TypeAlias
from reportlab.pdfgen.canvas import Canvas
@@ -33,6 +33,7 @@ __all__ = (
# type vars didn't seem to work for this one
_PageCallback: TypeAlias = Callable[[Canvas, Any], object]
@type_check_only
class _CanvasMaker(Protocol):
# NOTE: This matches a subset of Canvas.__init__
def __call__(
@@ -1,6 +1,6 @@
from _typeshed import Incomplete, SupportsRead, Unused
from collections.abc import Callable, Iterable, Sequence
from typing import Any, Literal, NoReturn, Protocol
from typing import Any, Literal, NoReturn, Protocol, type_check_only
from typing_extensions import Self, TypeAlias
from reportlab.lib.colors import Color
@@ -64,6 +64,7 @@ _FlowableSublist: TypeAlias = Flowable | list[Flowable] | tuple[Flowable, ...]
# NOTE: Technically can only be list or tuple, but would be annoying for variance
_NestedFlowable: TypeAlias = Flowable | Sequence[_NestedFlowable]
@type_check_only
class _StyledFlowableFactory(Protocol):
# NOTE: We leave style at Any so people can specify a specifc property set
def __call__(self, value: str, /, *, style: Any) -> Flowable: ...
+4 -1
View File
@@ -1,6 +1,6 @@
from _typeshed import Incomplete, Unused
from collections.abc import Callable, Mapping
from typing import Any, Final, Literal, Protocol, TypedDict, TypeVar, overload
from typing import Any, Final, Literal, Protocol, TypedDict, TypeVar, overload, type_check_only
from typing_extensions import TypeAlias, Unpack
from reportlab.lib.colors import Color
@@ -15,14 +15,17 @@ _Op: TypeAlias = _SupportsWidthAndExecute | str | float | tuple[str, Unpack[tupl
# NOTE: Output from pyRXP xml parser
_ParsedText: TypeAlias = tuple[str, dict[str, Any], list[_ParsedText], Any] | list[_ParsedText] | str
@type_check_only
class _LineOpHandler(Protocol):
def start_at(self, x: float, y: float, para: paragraphEngine, canvas: Canvas, textobject: PDFTextObject) -> None: ...
def end_at(self, x: float, y: float, para: paragraphEngine, canvas: Canvas, textobject: PDFTextObject) -> None: ...
@type_check_only
class _SupportsWidthAndExecute(Protocol):
def width(self, engine) -> float: ...
def execute(self, engine, textobject: PDFTextObject, canvas: Canvas) -> object: ...
@type_check_only
class _SimpleStyleKwargs(TypedDict, total=False):
fontName: str
fontSize: float
@@ -1,6 +1,6 @@
from _typeshed import Unused
from collections.abc import Callable, Iterable, Sequence
from typing import Any, Final, Literal, TypedDict, TypeVar, overload
from typing import Any, Final, Literal, TypedDict, TypeVar, overload, type_check_only
from typing_extensions import TypeAlias, Unpack
from reportlab.lib.styles import ParagraphStyle, PropertySet
@@ -12,6 +12,7 @@ _T = TypeVar("_T")
_Entry: TypeAlias = tuple[int, str, int] | tuple[int, str, int, str | None] | Sequence[int | str | None]
_SequencerFormat: TypeAlias = Literal["I", "i", "123", "ABC", "abc"]
@type_check_only
class _TableOfContentsKwargs(TypedDict, total=False):
rightColumnWidth: float
levelStyles: list[PropertySet] # should be ParagraphStyle
@@ -19,6 +20,7 @@ class _TableOfContentsKwargs(TypedDict, total=False):
dotsMinLevel: int
formatter: Callable[[int], str] | None
@type_check_only
class _SimpleIndexKwargs(TypedDict, total=False):
style: Iterable[PropertySet] | PropertySet | None # should be ParagraphStyle
dot: str | None