From 1cfb5bb5a1e54716a864ca7888e49229a13b8da0 Mon Sep 17 00:00:00 2001 From: Darshan <36774606+darshanip@users.noreply.github.com> Date: Fri, 14 Oct 2022 23:38:07 +0530 Subject: [PATCH] Add return types to fpdf.drawing (#8891) Co-authored-by: Akuli Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- stubs/fpdf2/fpdf/drawing.pyi | 69 +++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/stubs/fpdf2/fpdf/drawing.pyi b/stubs/fpdf2/fpdf/drawing.pyi index dab5b9eac..a29ae2281 100644 --- a/stubs/fpdf2/fpdf/drawing.pyi +++ b/stubs/fpdf2/fpdf/drawing.pyi @@ -1,18 +1,20 @@ import decimal from _typeshed import Incomplete, Self from collections import OrderedDict -from collections.abc import Generator -from contextlib import _GeneratorContextManager +from collections.abc import Callable, Generator, Iterator +from contextlib import contextmanager from re import Pattern -from typing import ClassVar, NamedTuple +from typing import Any, ClassVar, NamedTuple, TypeVar from typing_extensions import TypeAlias from .syntax import Name, Raw __pdoc__: dict[str, bool] -def force_nodocument(item): ... -def force_document(item): ... +_CallableT = TypeVar("_CallableT", bound=Callable[..., Any]) + +def force_nodocument(item: _CallableT) -> _CallableT: ... +def force_document(item: _CallableT) -> _CallableT: ... Number: TypeAlias = int | float | decimal.Decimal NumberClass: tuple[type, ...] @@ -23,10 +25,10 @@ STR_ESC: Pattern[str] STR_ESC_MAP: dict[str, str] class GraphicsStateDictRegistry(OrderedDict[Raw, Name]): - def register_style(self, style: GraphicsStyle): ... + def register_style(self, style: GraphicsStyle) -> Name | None: ... -def number_to_str(number): ... -def render_pdf_primitive(primitive): ... +def number_to_str(number) -> str: ... +def render_pdf_primitive(primitive) -> Raw: ... class DeviceRGB: OPERATOR: str @@ -49,11 +51,11 @@ class DeviceCMYK: def colors(self): ... def pdf_repr(self) -> str: ... -def rgb8(r, g, b, a: Incomplete | None = ...): ... -def gray8(g, a: Incomplete | None = ...): ... -def cmyk8(c, m, y, k, a: Incomplete | None = ...): ... -def color_from_hex_string(hexstr): ... -def color_from_rgb_string(rgbstr): ... +def rgb8(r, g, b, a: Incomplete | None = ...) -> DeviceRGB: ... +def gray8(g, a: Incomplete | None = ...) -> DeviceGray: ... +def cmyk8(c, m, y, k, a: Incomplete | None = ...) -> DeviceCMYK: ... +def color_from_hex_string(hexstr) -> DeviceRGB: ... +def color_from_rgb_string(rgbstr) -> DeviceRGB: ... class Point(NamedTuple): x: Number @@ -322,25 +324,26 @@ class PaintedPath: def clipping_path(self): ... @clipping_path.setter def clipping_path(self, new_clipath) -> None: ... - def transform_group(self, transform) -> _GeneratorContextManager[Incomplete]: ... + @contextmanager + def transform_group(self: Self, transform) -> Iterator[Self]: ... def add_path_element(self, item, _copy: bool = ...) -> None: ... - def rectangle(self, x, y, w, h, rx: int = ..., ry: int = ...): ... - def circle(self, cx, cy, r): ... - def ellipse(self, cx, cy, rx, ry): ... - def move_to(self, x, y): ... - def move_relative(self, x, y): ... - def line_to(self, x, y): ... - def line_relative(self, dx, dy): ... - def horizontal_line_to(self, x): ... - def horizontal_line_relative(self, dx): ... - def vertical_line_to(self, y): ... - def vertical_line_relative(self, dy): ... - def curve_to(self, x1, y1, x2, y2, x3, y3): ... - def curve_relative(self, dx1, dy1, dx2, dy2, dx3, dy3): ... - def quadratic_curve_to(self, x1, y1, x2, y2): ... - def quadratic_curve_relative(self, dx1, dy1, dx2, dy2): ... - def arc_to(self, rx, ry, rotation, large_arc, positive_sweep, x, y): ... - def arc_relative(self, rx, ry, rotation, large_arc, positive_sweep, dx, dy): ... + def rectangle(self: Self, x, y, w, h, rx: int = ..., ry: int = ...) -> Self: ... + def circle(self: Self, cx, cy, r) -> Self: ... + def ellipse(self: Self, cx, cy, rx, ry) -> Self: ... + def move_to(self: Self, x, y) -> Self: ... + def move_relative(self: Self, x, y) -> Self: ... + def line_to(self: Self, x, y) -> Self: ... + def line_relative(self: Self, dx, dy) -> Self: ... + def horizontal_line_to(self: Self, x) -> Self: ... + def horizontal_line_relative(self: Self, dx) -> Self: ... + def vertical_line_to(self: Self, y) -> Self: ... + def vertical_line_relative(self: Self, dy) -> Self: ... + def curve_to(self: Self, x1, y1, x2, y2, x3, y3) -> Self: ... + def curve_relative(self: Self, dx1, dy1, dx2, dy2, dx3, dy3) -> Self: ... + def quadratic_curve_to(self: Self, x1, y1, x2, y2) -> Self: ... + def quadratic_curve_relative(self: Self, dx1, dy1, dx2, dy2) -> Self: ... + def arc_to(self: Self, rx, ry, rotation, large_arc, positive_sweep, x, y) -> Self: ... + def arc_relative(self: Self, rx, ry, rotation, large_arc, positive_sweep, dx, dy) -> Self: ... def close(self) -> None: ... def render( self, gsd_registry, style, last_item, initial_point, debug_stream: Incomplete | None = ..., pfx: Incomplete | None = ... @@ -361,11 +364,11 @@ class GraphicsContext: def __init__(self) -> None: ... def __deepcopy__(self: Self, memo) -> Self: ... @property - def transform(self): ... + def transform(self) -> Transform | None: ... @transform.setter def transform(self, tf) -> None: ... @property - def clipping_path(self): ... + def clipping_path(self) -> ClippingPath | None: ... @clipping_path.setter def clipping_path(self, new_clipath) -> None: ... def add_item(self, item, _copy: bool = ...) -> None: ...