From 2649b827f41ee2c34403c54179d1c308a8505669 Mon Sep 17 00:00:00 2001 From: Matthias Schoettle Date: Thu, 26 Oct 2023 11:00:59 -0400 Subject: [PATCH 01/17] add compatibility with fpdf2 2.7.6 --- stubs/fpdf2/METADATA.toml | 2 +- stubs/fpdf2/fpdf/fpdf.pyi | 14 +++++++------- stubs/fpdf2/fpdf/html.pyi | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/stubs/fpdf2/METADATA.toml b/stubs/fpdf2/METADATA.toml index a47fe4aef28d..f531f358fc41 100644 --- a/stubs/fpdf2/METADATA.toml +++ b/stubs/fpdf2/METADATA.toml @@ -1,4 +1,4 @@ -version = "2.7.4" +version = "2.7.6" upstream_repository = "https://github.com/PyFPDF/fpdf2" requires = ["types-Pillow>=9.2.0"] diff --git a/stubs/fpdf2/fpdf/fpdf.pyi b/stubs/fpdf2/fpdf/fpdf.pyi index d1607c6e106a..1e3b0e0aba1a 100644 --- a/stubs/fpdf2/fpdf/fpdf.pyi +++ b/stubs/fpdf2/fpdf/fpdf.pyi @@ -397,7 +397,7 @@ class FPDF(GraphicsStateMixin): color: Sequence[float] = (1, 1, 0), border_width: int = 1, ) -> AnnotationDict: ... - def text(self, x: float, y: float, txt: str = "") -> None: ... + def text(self, x: float, y: float, text: str = "") -> None: ... def rotate(self, angle: float, x: float | None = None, y: float | None = None) -> None: ... def rotation(self, angle: float, x: float | None = None, y: float | None = None) -> _GeneratorContextManager[None]: ... def skew( @@ -421,7 +421,7 @@ class FPDF(GraphicsStateMixin): self, w: float | None = None, h: float | None = None, - txt: str = "", + text: str = "", border: bool | Literal[0, 1] | str = 0, ln: int | Literal["DEPRECATED"] = "DEPRECATED", align: str | Align = ..., @@ -438,7 +438,7 @@ class FPDF(GraphicsStateMixin): self, w: float, h: float | None = None, - txt: str = "", + text: str = "", border: bool | Literal[0, 1] | str = 0, align: str | Align = ..., fill: bool = False, @@ -455,7 +455,7 @@ class FPDF(GraphicsStateMixin): output: MethodReturnValue | str | int = ..., ): ... def write( - self, h: float | None = None, txt: str = "", link: str = "", print_sh: bool = False, wrapmode: WrapMode = ... + self, h: float | None = None, text: str = "", link: str = "", print_sh: bool = False, wrapmode: WrapMode = ... ) -> bool: ... def image( self, @@ -480,7 +480,7 @@ class FPDF(GraphicsStateMixin): def get_y(self) -> float: ... def set_y(self, y: float) -> None: ... def set_xy(self, x: float, y: float) -> None: ... - def normalize_text(self, txt: str) -> str: ... + def normalize_text(self, text: str) -> str: ... def sign_pkcs12( self, pkcs_filepath: str, @@ -505,8 +505,8 @@ class FPDF(GraphicsStateMixin): flags: tuple[AnnotationFlag, ...] = ..., ) -> None: ... def file_id(self) -> str: ... - def interleaved2of5(self, txt, x: float, y: float, w: float = 1, h: float = 10) -> None: ... - def code39(self, txt, x: float, y: float, w: float = 1.5, h: float = 5) -> None: ... + def interleaved2of5(self, text, x: float, y: float, w: float = 1, h: float = 10) -> None: ... + def code39(self, text, x: float, y: float, w: float = 1.5, h: float = 5) -> None: ... def rect_clip(self, x: float, y: float, w: float, h: float) -> _GeneratorContextManager[None]: ... def elliptic_clip(self, x: float, y: float, w: float, h: float) -> _GeneratorContextManager[None]: ... def round_clip(self, x: float, y: float, r: float) -> _GeneratorContextManager[None]: ... diff --git a/stubs/fpdf2/fpdf/html.pyi b/stubs/fpdf2/fpdf/html.pyi index 08516948d182..fb459ec27151 100644 --- a/stubs/fpdf2/fpdf/html.pyi +++ b/stubs/fpdf2/fpdf/html.pyi @@ -83,7 +83,7 @@ class HTML2FPDF(HTMLParser): def set_font(self, face: Incomplete | None = None, size: Incomplete | None = None) -> None: ... def set_style(self, tag: Incomplete | None = None, enable: bool = False) -> None: ... def set_text_color(self, r: Incomplete | None = None, g: int = 0, b: int = 0) -> None: ... - def put_link(self, txt) -> None: ... + def put_link(self, text) -> None: ... def render_toc(self, pdf, outline) -> None: ... def error(self, message: str) -> None: ... From 4a219b64978bf37d456bcc4adda7ee3669364f73 Mon Sep 17 00:00:00 2001 From: Matthias Schoettle Date: Fri, 27 Oct 2023 10:51:36 -0400 Subject: [PATCH 02/17] update stubs --- stubs/fpdf2/fpdf/__init__.pyi | 1 + stubs/fpdf2/fpdf/deprecation.pyi | 4 ++++ stubs/fpdf2/fpdf/fpdf.pyi | 31 ++++++++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/stubs/fpdf2/fpdf/__init__.pyi b/stubs/fpdf2/fpdf/__init__.pyi index 9d17a7f7e84f..0ba2c5cfbfc9 100644 --- a/stubs/fpdf2/fpdf/__init__.pyi +++ b/stubs/fpdf2/fpdf/__init__.pyi @@ -17,6 +17,7 @@ __all__ = [ "FPDF", "FPDFException", "Align", + "TextMode", "XPos", "YPos", "Template", diff --git a/stubs/fpdf2/fpdf/deprecation.pyi b/stubs/fpdf2/fpdf/deprecation.pyi index 89ab11760b95..a1399a56191a 100644 --- a/stubs/fpdf2/fpdf/deprecation.pyi +++ b/stubs/fpdf2/fpdf/deprecation.pyi @@ -1,7 +1,11 @@ from types import ModuleType from typing import Any, NoReturn +def support_deprecated_txt_arg(fn): ... + class WarnOnDeprecatedModuleAttributes(ModuleType): def __call__(self) -> NoReturn: ... def __getattr__(self, name: str) -> Any: ... def __setattr__(self, name: str, value: Any) -> None: ... + +def get_stack_level() -> int: ... diff --git a/stubs/fpdf2/fpdf/fpdf.pyi b/stubs/fpdf2/fpdf/fpdf.pyi index 1e3b0e0aba1a..a6c726d021c5 100644 --- a/stubs/fpdf2/fpdf/fpdf.pyi +++ b/stubs/fpdf2/fpdf/fpdf.pyi @@ -1,6 +1,6 @@ import datetime from _typeshed import Incomplete, StrPath, Unused -from collections.abc import Callable, Iterable, Sequence +from collections.abc import Callable, Generator, Iterable, Sequence from contextlib import _GeneratorContextManager from io import BytesIO from pathlib import PurePath @@ -200,6 +200,14 @@ class FPDF(GraphicsStateMixin): zoom: Literal["fullpage", "fullwidth", "real", "default"] | float, layout: Literal["single", "continuous", "two", "default"] = "continuous", ) -> None: ... + def set_text_shaping( + self, + use_shaping_engine: bool = True, + features: dict[str, bool] | None = None, + direction: Literal["ltr", "rtl"] | None = None, + script: str | None = None, + language: str | None = None, + ): ... def set_compression(self, compress: bool) -> None: ... title: str def set_title(self, title: str) -> None: ... @@ -403,6 +411,7 @@ class FPDF(GraphicsStateMixin): def skew( self, ax: float = 0, ay: float = 0, x: float | None = None, y: float | None = None ) -> _GeneratorContextManager[None]: ... + def mirror(self, origin, angle) -> Generator[None, None, None]: ... def local_context( self, font_family: Incomplete | None = None, @@ -427,7 +436,7 @@ class FPDF(GraphicsStateMixin): align: str | Align = ..., fill: bool = False, link: str = "", - center: bool | Literal["DEPRECATED"] = "DEPRECATED", + center: bool = False, markdown: bool = False, new_x: XPos | str = ..., new_y: YPos | str = ..., @@ -443,8 +452,8 @@ class FPDF(GraphicsStateMixin): align: str | Align = ..., fill: bool = False, split_only: bool = False, - link: str | int = "", ln: int | Literal["DEPRECATED"] = "DEPRECATED", + link: str | int = "", max_line_height: float | None = None, markdown: bool = False, print_sh: bool = False, @@ -453,10 +462,26 @@ class FPDF(GraphicsStateMixin): wrapmode: WrapMode = ..., dry_run: bool = False, output: MethodReturnValue | str | int = ..., + center: bool = False, + padding: int = 0, ): ... def write( self, h: float | None = None, text: str = "", link: str = "", print_sh: bool = False, wrapmode: WrapMode = ... ) -> bool: ... + def text_columns( + self, + text: str | None = None, + ncols: int = 1, + gutter: float = 10, + balance: bool = False, + text_align: Align | str = "LEFT", + line_height: float = 1, + l_margin: float | None = None, + r_margin: float | None = None, + print_sh: bool = False, + wrapmode: WrapMode = ..., + skip_leading_spaces: bool = False, + ): ... def image( self, name: str | Image.Image | BytesIO | StrPath, From f7c39f1dea2c4929cdd3a5b13e4a79977fdf16d9 Mon Sep 17 00:00:00 2001 From: Matthias Schoettle Date: Fri, 27 Oct 2023 11:20:28 -0400 Subject: [PATCH 03/17] update stubs --- stubs/fpdf2/fpdf/html.pyi | 2 +- stubs/fpdf2/fpdf/text_region.pyi | 98 ++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 stubs/fpdf2/fpdf/text_region.pyi diff --git a/stubs/fpdf2/fpdf/html.pyi b/stubs/fpdf2/fpdf/html.pyi index fb459ec27151..519d17654ac5 100644 --- a/stubs/fpdf2/fpdf/html.pyi +++ b/stubs/fpdf2/fpdf/html.pyi @@ -80,7 +80,7 @@ class HTML2FPDF(HTMLParser): def handle_data(self, data) -> None: ... def handle_starttag(self, tag, attrs) -> None: ... def handle_endtag(self, tag) -> None: ... - def set_font(self, face: Incomplete | None = None, size: Incomplete | None = None) -> None: ... + def set_font(self, face: Incomplete | None = None, size: Incomplete | None = None, set_default: bool = False) -> None: ... def set_style(self, tag: Incomplete | None = None, enable: bool = False) -> None: ... def set_text_color(self, r: Incomplete | None = None, g: int = 0, b: int = 0) -> None: ... def put_link(self, text) -> None: ... diff --git a/stubs/fpdf2/fpdf/text_region.pyi b/stubs/fpdf2/fpdf/text_region.pyi new file mode 100644 index 000000000000..46aa47da8177 --- /dev/null +++ b/stubs/fpdf2/fpdf/text_region.pyi @@ -0,0 +1,98 @@ +from _typeshed import Incomplete +from collections.abc import Sequence +from typing import NamedTuple + +from .enums import Align, WrapMode + +class Extents(NamedTuple): + left: float + right: float + +class TextRegionMixin: + def __init__(self, *args, **kwargs) -> None: ... + def register_text_region(self, region) -> None: ... + def is_current_text_region(self, region): ... + def clear_text_region(self) -> None: ... + +class LineWrapper(NamedTuple): + line: Sequence[Incomplete] + paragraph: Paragraph + first_line: bool = False + last_line: bool = False + +class Paragraph: + pdf: Incomplete + text_align: Incomplete + line_height: Incomplete + top_margin: Incomplete + bottom_margin: Incomplete + skip_leading_spaces: Incomplete + wrapmode: Incomplete + + def __init__( + self, + region, + text_align: Incomplete | None = None, + line_height: Incomplete | None = None, + top_margin: float = 0, + bottom_margin: float = 0, + skip_leading_spaces: bool = False, + wrapmode: WrapMode | None = None, + ) -> None: ... + def __enter__(self): ... + def __exit__(self, exc_type, exc_value, traceback) -> None: ... + def write(self, text: str, link: Incomplete | None = None): ... + def ln(self, h: float | None = None) -> None: ... + def build_lines(self, print_sh: bool) -> list[LineWrapper]: ... + +class ParagraphCollectorMixin: + pdf: Incomplete + text_align: Align | str = "LEFT" + line_height: Incomplete + print_sh: Incomplete + wrapmode: Incomplete + skip_leading_spaces: Incomplete + def __init__( + self, + pdf, + *args, + text: str | None = None, + text_align: str = "LEFT", + line_height: float = 1.0, + print_sh: bool = False, + skip_leading_spaces: bool = False, + wrapmode: WrapMode | None = None, + **kwargs, + ) -> None: ... + def __enter__(self): ... + def __exit__(self, exc_type, exc_value, traceback) -> None: ... + def write(self, text: str, link: Incomplete | None = None): ... + def ln(self, h: float | None = None) -> None: ... + def paragraph( + self, + text_align: Incomplete | None = None, + line_height: Incomplete | None = None, + skip_leading_spaces: bool = False, + top_margin: int = 0, + bottom_margin: int = 0, + wrapmode: WrapMode | None = None, + ): ... + def end_paragraph(self) -> None: ... + +class TextRegion(ParagraphCollectorMixin): + def current_x_extents(self, y, height) -> None: ... + def collect_lines(self): ... + def render(self) -> None: ... + def get_width(self, height): ... + +class TextColumnarMixin: + l_margin: Incomplete + r_margin: Incomplete + def __init__(self, pdf, *args, l_margin: Incomplete | None = None, r_margin: Incomplete | None = None, **kwargs) -> None: ... + +class TextColumns(TextRegion, TextColumnarMixin): + balance: Incomplete + def __init__(self, pdf, *args, ncols: int = 1, gutter: float = 10, balance: bool = False, **kwargs) -> None: ... + def __enter__(self): ... + def render(self) -> None: ... + def current_x_extents(self, y, height): ... From cfb12953ec8131bbe4c0f8b1c3df5ad5e03d140e Mon Sep 17 00:00:00 2001 From: Matthias Schoettle Date: Fri, 27 Oct 2023 13:15:26 -0400 Subject: [PATCH 04/17] update stubs --- stubs/fpdf2/fpdf/enums.pyi | 16 ++++++++++++++++ stubs/fpdf2/fpdf/fpdf.pyi | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/stubs/fpdf2/fpdf/enums.pyi b/stubs/fpdf2/fpdf/enums.pyi index 112de3d17759..a7001c3930bc 100644 --- a/stubs/fpdf2/fpdf/enums.pyi +++ b/stubs/fpdf2/fpdf/enums.pyi @@ -37,6 +37,11 @@ class Align(CoerciveEnum): R: str J: str +class VAlign(CoerciveEnum): + M: str + T: str + B: str + class TextEmphasis(CoerciveIntFlag): B: int I: int @@ -103,6 +108,16 @@ class YPos(CoerciveEnum): TMARGIN: str BMARGIN: str +class Angle(CoerciveIntEnum): + NORTH: int + EAST: int + SOUTH: int + WEST: int + NORTHEAST: int + SOUTHEAST: int + SOUTHWEST: int + NORTHWEST: int + class PageLayout(CoerciveEnum): SINGLE_PAGE: Name ONE_COLUMN: Name @@ -236,3 +251,4 @@ class EncryptionMethod(Enum): NO_ENCRYPTION: int RC4: int AES_128: int + AES_256: int diff --git a/stubs/fpdf2/fpdf/fpdf.pyi b/stubs/fpdf2/fpdf/fpdf.pyi index a6c726d021c5..33a9d6ed8b2f 100644 --- a/stubs/fpdf2/fpdf/fpdf.pyi +++ b/stubs/fpdf2/fpdf/fpdf.pyi @@ -101,6 +101,7 @@ class FPDF(GraphicsStateMixin): MARKDOWN_UNDERLINE_MARKER: ClassVar[str] MARKDOWN_LINK_REGEX: ClassVar[Pattern[str]] MARKDOWN_LINK_COLOR: ClassVar[Incomplete | None] + MARKDOWN_LINK_UNDERLINE: ClassVar[bool] HTML2FPDF_CLASS: ClassVar[type[HTML2FPDF]] @@ -452,8 +453,8 @@ class FPDF(GraphicsStateMixin): align: str | Align = ..., fill: bool = False, split_only: bool = False, + link: str = "", ln: int | Literal["DEPRECATED"] = "DEPRECATED", - link: str | int = "", max_line_height: float | None = None, markdown: bool = False, print_sh: bool = False, From 4ca72f70e531569350574f761e0e71d341cc81e7 Mon Sep 17 00:00:00 2001 From: Matthias Schoettle Date: Fri, 27 Oct 2023 13:37:57 -0400 Subject: [PATCH 05/17] update fonts --- stubs/fpdf2/fpdf/fonts.pyi | 76 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/stubs/fpdf2/fpdf/fonts.pyi b/stubs/fpdf2/fpdf/fonts.pyi index b559d9f76062..6fa0084f6540 100644 --- a/stubs/fpdf2/fpdf/fonts.pyi +++ b/stubs/fpdf2/fpdf/fonts.pyi @@ -1,9 +1,11 @@ import dataclasses from _typeshed import Incomplete +from collections.abc import Generator from dataclasses import dataclass from .drawing import DeviceGray, DeviceRGB, Number from .enums import TextEmphasis +from .syntax import PDFObject @dataclass class FontFace: @@ -24,5 +26,79 @@ class FontFace: replace = dataclasses.replace +class FontMixin: + i: int + type: str + name: str + up: int + ut: int + cw: int + fontkey: str + emphasis: TextEmphasis + def encode_text(self, text: str): ... + +class CoreFont(FontMixin): + def __init__(self, fpdf, fontkey: str, style: int) -> None: ... + def get_text_width(self, text: str, font_size_pt: int, _): ... + +class TTFFont(FontMixin): + ttffile: Incomplete + ttfont: Incomplete + scale: Incomplete + desc: Incomplete + cmap: Incomplete + glyph_ids: Incomplete + missing_glyphs: Incomplete + subset: Incomplete + hbfont: Incomplete + def __init__(self, fpdf, font_file_path, fontkey: str, style: int) -> None: ... + def close(self) -> None: ... + def get_text_width(self, text: str, font_size_pt: int, text_shaping_parms): ... + def shaped_text_width(self, text: str, font_size_pt: int, text_shaping_parms): ... + def perform_harfbuzz_shaping(self, text: str, font_size_pt: int, text_shaping_parms): ... + def shape_text(self, text: str, font_size_pt: int, text_shaping_parms): ... + +class PDFFontDescriptor(PDFObject): + type: Incomplete + ascent: Incomplete + descent: Incomplete + cap_height: Incomplete + flags: Incomplete + font_b_box: Incomplete + italic_angle: Incomplete + stem_v: Incomplete + missing_width: Incomplete + font_name: Incomplete + def __init__(self, ascent, descent, cap_height, flags, font_b_box, italic_angle, stem_v, missing_width) -> None: ... + +class Glyph: + glyph_id: int + unicode: tuple[Incomplete] + glyph_name: str + glyph_width: int + def __hash__(self): ... + def __init__(self, glyph_id, unicode, glyph_name, glyph_width) -> None: ... + def __lt__(self, other): ... + def __gt__(self, other): ... + def __le__(self, other): ... + def __ge__(self, other): ... + +class SubsetMap: + font: TTFFont + def __init__(self, font: TTFFont, identities: list[int]) -> None: ... + def __len__(self) -> int: ... + def items(self) -> Generator[Incomplete, None, None]: ... + def pick(self, unicode: int): ... + def pick_glyph(self, glyph): ... + def get_glyph( + self, + glyph: Incomplete | None = None, + unicode: Incomplete | None = None, + glyph_name: Incomplete | None = None, + glyph_width: Incomplete | None = None, + ) -> Glyph: ... + def get_all_glyph_names(self): ... + +CORE_FONTS: dict[str, str] COURIER_FONT: dict[str, int] CORE_FONTS_CHARWIDTHS: dict[str, dict[str, int]] From b4ced804259359bd7ebaa4ad1b34f8f0de5b559a Mon Sep 17 00:00:00 2001 From: Matthias Schoettle Date: Mon, 30 Oct 2023 17:15:18 -0400 Subject: [PATCH 06/17] update stubs --- stubs/fpdf2/fpdf/table.pyi | 22 ++++++++++++++++++++-- stubs/fpdf2/fpdf/util.pyi | 13 ++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/stubs/fpdf2/fpdf/table.pyi b/stubs/fpdf2/fpdf/table.pyi index 4586a178d8ff..17579ca735e9 100644 --- a/stubs/fpdf2/fpdf/table.pyi +++ b/stubs/fpdf2/fpdf/table.pyi @@ -7,16 +7,19 @@ from typing_extensions import Literal from PIL import Image from .drawing import DeviceGray, DeviceRGB -from .enums import Align, TableBordersLayout, TableCellFillMode +from .enums import Align, TableBordersLayout, TableCellFillMode, VAlign, WrapMode from .fonts import FontFace from .fpdf import FPDF +from .util import Padding DEFAULT_HEADINGS_STYLE: FontFace +def draw_box_borders(pdf: FPDF, x1, y1, x2, y2, border: str | Literal[0, 1], fill_color: Incomplete | None = None) -> None: ... @dataclass(frozen=True) class RowLayoutInfo: height: int triggers_page_jump: bool + rendered_height: dict[Incomplete, Incomplete] class Table: rows: list[Row] @@ -27,16 +30,23 @@ class Table: rows: Iterable[str] = (), *, align: str | Align = "CENTER", + v_align: str | VAlign = "MIDDLE", borders_layout: str | TableBordersLayout = ..., cell_fill_color: int | tuple[Incomplete, ...] | DeviceGray | DeviceRGB | None = None, cell_fill_mode: str | TableCellFillMode = ..., col_widths: int | tuple[int, ...] | None = None, first_row_as_headings: bool = True, + gutter_height: float = 0, + gutter_width: float = 0, headings_style: FontFace = ..., line_height: int | None = None, - markdown=False, + markdown: bool = False, text_align: str | Align = "JUSTIFY", width: int | None = None, + wrapmode: WrapMode = ..., + padding: float | Padding | None = None, + outer_border_width: float | None = None, + num_heading_rows: int = 1, ) -> None: ... def row(self, cells: Iterable[str] = ()) -> Row: ... def render(self) -> None: ... @@ -48,23 +58,31 @@ class Row: def __init__(self, fpdf: FPDF) -> None: ... @property def cols_count(self) -> int: ... + @property + def column_indices(self): ... def cell( self, text: str = "", align: str | Align | None = None, + v_align: str | VAlign | None = None, style: FontFace | None = None, img: str | Image.Image | BytesIO | None = None, img_fill_width: bool = False, colspan: int = 1, + padding: tuple[float, ...] | None = None, + link: str | int | None = None, ) -> Cell: ... @dataclass class Cell: text: str align: str | Align | None + v_align: str | VAlign | None style: FontFace | None img: str | None img_fill_width: bool colspan: int + padding: int | tuple[float, ...] | None + link: str | int | None def write(self, text, align: Incomplete | None = None): ... diff --git a/stubs/fpdf2/fpdf/util.pyi b/stubs/fpdf2/fpdf/util.pyi index d078ec0ab391..ab80b8abdffe 100644 --- a/stubs/fpdf2/fpdf/util.pyi +++ b/stubs/fpdf2/fpdf/util.pyi @@ -1,13 +1,24 @@ from collections.abc import Iterable -from typing import Any, AnyStr +from typing import Any, AnyStr, NamedTuple from typing_extensions import Final, Literal, TypeAlias _Unit: TypeAlias = Literal["pt", "mm", "cm", "in"] PIL_MEM_BLOCK_SIZE_IN_MIB: Final = 16 +class Padding(NamedTuple): + # TODO: replaced Number with float + top: float = ... + right: float = ... + bottom: float = ... + left: float = ... + @classmethod + def new(cls, padding: float | tuple[float, ...] | list[float]): ... + def buffer_subst(buffer: bytearray, placeholder: str, value: str) -> bytearray: ... def escape_parens(s: AnyStr) -> AnyStr: ... + +# TODO: change float to Number? def get_scale_factor(unit: _Unit | float) -> float: ... def convert_unit( # to_convert has a recursive type From 90056f5886edd19875149f9c09381a7df2e0451b Mon Sep 17 00:00:00 2001 From: Matthias Schoettle Date: Mon, 30 Oct 2023 17:18:59 -0400 Subject: [PATCH 07/17] update stubs --- stubs/fpdf2/fpdf/output.pyi | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/stubs/fpdf2/fpdf/output.pyi b/stubs/fpdf2/fpdf/output.pyi index 1b01fb9fcd97..03b078a7f6b8 100644 --- a/stubs/fpdf2/fpdf/output.pyi +++ b/stubs/fpdf2/fpdf/output.pyi @@ -39,19 +39,6 @@ class PDFFont(PDFObject): w: Incomplete | None = None, ) -> None: ... -class PDFFontDescriptor(PDFObject): - type: Name - ascent: Incomplete - descent: Incomplete - cap_height: Incomplete - flags: Incomplete - font_b_box: Incomplete - italic_angle: Incomplete - stem_v: Incomplete - missing_width: Incomplete - font_name: Incomplete | None - def __init__(self, ascent, descent, cap_height, flags, font_b_box, italic_angle, stem_v, missing_width) -> None: ... - class CIDSystemInfo(PDFObject): registry: PDFString ordering: PDFString From 8579d9f050cd72f50df19d8e3ed3eed995880823 Mon Sep 17 00:00:00 2001 From: Matthias Schoettle Date: Tue, 31 Oct 2023 11:54:37 -0400 Subject: [PATCH 08/17] update stubs --- stubs/fpdf2/fpdf/html.pyi | 26 ++++++---------- stubs/fpdf2/fpdf/line_break.pyi | 54 ++++++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 27 deletions(-) diff --git a/stubs/fpdf2/fpdf/html.pyi b/stubs/fpdf2/fpdf/html.pyi index 519d17654ac5..25ea7f1da1f1 100644 --- a/stubs/fpdf2/fpdf/html.pyi +++ b/stubs/fpdf2/fpdf/html.pyi @@ -2,7 +2,6 @@ from _typeshed import Incomplete, SupportsKeysAndGetItem, Unused from collections.abc import Callable, Iterable from html.parser import HTMLParser from logging import Logger -from re import Match, Pattern from typing import ClassVar from typing_extensions import Final @@ -14,31 +13,32 @@ __copyright__: Final[str] LOGGER: Logger BULLET_WIN1252: Final[str] DEFAULT_HEADING_SIZES: dict[str, int] -LEADING_SPACE: Pattern[str] -WHITESPACE: Pattern[str] -TRAILING_SPACE: Pattern[str] COLOR_DICT: Final[dict[str, str]] -def px2mm(px: float) -> float: ... def color_as_decimal(color: str | None = "#000000") -> tuple[int, int, int] | None: ... class HTML2FPDF(HTMLParser): HTML_UNCLOSED_TAGS: ClassVar[tuple[str, ...]] - pdf: Incomplete + pdf: FPDF image_map: Incomplete - li_tag_indent: Incomplete - table_line_separators: Incomplete - ul_bullet_char: Incomplete + li_tag_indent: int + dd_tag_indent: int + ul_bullet_char: str + heading_sizes: dict[str, int] + pre_code_font: str + warn_on_tags_not_matching: bool style: Incomplete + font_size: Incomplete + follows_trailing_space: bool + follows_heading: bool href: str align: str page_links: Incomplete font_stack: Incomplete indent: int bullet: Incomplete - font_size: Incomplete font_color: Incomplete table: Incomplete table_col_width: Incomplete @@ -54,11 +54,8 @@ class HTML2FPDF(HTMLParser): theader_out: bool table_row_height: int heading_level: Incomplete - heading_sizes: dict[str, int] heading_above: float heading_below: float - pre_code_font: str - warn_on_tags_not_matching: bool # Not initialized in __init__: font_face: Incomplete @@ -87,8 +84,5 @@ class HTML2FPDF(HTMLParser): def render_toc(self, pdf, outline) -> None: ... def error(self, message: str) -> None: ... -def leading_whitespace_repl(matchobj: Match[str]) -> str: ... -def whitespace_repl(matchobj: Match[str]) -> str: ... - class HTMLMixin: def __init__(self, *args: Incomplete, **kwargs: Incomplete) -> None: ... diff --git a/stubs/fpdf2/fpdf/line_break.pyi b/stubs/fpdf2/fpdf/line_break.pyi index 55a601e09c9a..0aed91eaaf67 100644 --- a/stubs/fpdf2/fpdf/line_break.pyi +++ b/stubs/fpdf2/fpdf/line_break.pyi @@ -1,12 +1,13 @@ from _typeshed import Incomplete -from collections.abc import Sequence +from collections.abc import Callable, Sequence from typing import NamedTuple -from .enums import WrapMode +from .enums import Align, WrapMode SOFT_HYPHEN: str HYPHEN: str SPACE: str +NBSP: str NEWLINE: str class Fragment: @@ -15,7 +16,7 @@ class Fragment: k: float url: str | None def __init__( - self, characters: list[str] | str, graphics_state: dict[str, Incomplete], k: float, url: str | None = None + self, characters: list[str] | str, graphics_state: dict[str, Incomplete], k: float, link: str | int | None = None ) -> None: ... @property def font(self): ... @@ -57,12 +58,28 @@ class Fragment: def __eq__(self, other: Fragment) -> bool: ... # type: ignore[override] def get_width(self, start: int = 0, end: int | None = None, chars: str | None = None, initial_cs: bool = True): ... def get_character_width(self, character: str, print_sh: bool = False, initial_cs: bool = True): ... + def render_pdf_text( + self, + frag_ws: Incomplete, + current_ws: Incomplete, + word_spacing: Incomplete, + adjust_x: Incomplete, + adjust_y: Incomplete, + h: Incomplete, + ): ... + def render_pdf_text_ttf(self, frag_ws: Incomplete, word_spacing: Incomplete): ... + def render_with_text_shaping( + self, pos_x: Incomplete, pos_y: Incomplete, h: Incomplete, word_spacing: Incomplete, text_shaping_parms: Incomplete + ): ... + def render_pdf_text_core(self, frag_ws: Incomplete, current_ws: Incomplete): ... class TextLine(NamedTuple): fragments: tuple[Incomplete, ...] text_width: float number_of_spaces: int - justify: bool + align: Align + height: float + max_width: float trailing_nl: bool = ... class SpaceHint(NamedTuple): @@ -86,9 +103,11 @@ class HyphenHint(NamedTuple): k: float class CurrentLine: + max_width: float print_sh: Incomplete fragments: Incomplete width: int + height: int number_of_spaces: int space_break_hint: Incomplete hyphen_break_hint: Incomplete @@ -101,22 +120,35 @@ class CurrentLine: k: float, original_fragment_index: int, original_character_index: int, + height: float, url: str | None = None, ): ... def trim_trailing_spaces(self) -> None: ... - def manual_break(self, justify: bool = False, trailing_nl: bool = False): ... + def manual_break(self, align: Align, trailing_nl: bool = False): ... def automatic_break_possible(self): ... - def automatic_break(self, justify: bool): ... + def automatic_break(self, align: Align): ... class MultiLineBreak: - styled_text_fragments: Sequence[Fragment] - justify: bool + fragments: Sequence[Fragment] + get_width: float + margins: Sequence[float] + align: Align print_sh: bool - wrap_mode: WrapMode + wrapmode: WrapMode + line_height: float + skip_leading_spaces: bool fragment_index: int character_index: int idx_last_forced_break: int | None def __init__( - self, styled_text_fragments: Sequence[Fragment], justify: bool = False, print_sh: bool = False, wrapmode: WrapMode = ... + self, + ragments: Sequence[Fragment], + max_width: float | Callable[[float], float], + margins: Sequence[float], + align: Align = ..., + print_sh: bool = False, + wrapmode: WrapMode = ..., + line_height: float = 1.0, + skip_leading_spaces: bool = False, ) -> None: ... - def get_line_of_given_width(self, maximum_width: float, wordsplit: bool = True): ... + def get_line(self): ... From 6121e4165efc9321646fbc97794053a89c945434 Mon Sep 17 00:00:00 2001 From: Matthias Schoettle Date: Tue, 31 Oct 2023 11:56:06 -0400 Subject: [PATCH 09/17] update stubs --- stubs/fpdf2/fpdf/fpdf.pyi | 6 ------ 1 file changed, 6 deletions(-) diff --git a/stubs/fpdf2/fpdf/fpdf.pyi b/stubs/fpdf2/fpdf/fpdf.pyi index 33a9d6ed8b2f..e2b0a38bba30 100644 --- a/stubs/fpdf2/fpdf/fpdf.pyi +++ b/stubs/fpdf2/fpdf/fpdf.pyi @@ -83,12 +83,6 @@ class ToCPlaceholder(NamedTuple): y: int pages: int = ... -class SubsetMap: - def __init__(self, identities: Iterable[int]) -> None: ... - def __len__(self) -> int: ... - def pick(self, unicode: int) -> int: ... - def dict(self) -> dict[int, int]: ... - def get_page_format(format: _Format | tuple[float, float], k: float | None = None) -> tuple[float, float]: ... # TODO: TypedDicts From bf8b39f10196f4157eb9a36417b36c3aa0f534db Mon Sep 17 00:00:00 2001 From: Matthias Schoettle Date: Tue, 31 Oct 2023 12:01:21 -0400 Subject: [PATCH 10/17] update stubs --- stubs/fpdf2/fpdf/fonts.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stubs/fpdf2/fpdf/fonts.pyi b/stubs/fpdf2/fpdf/fonts.pyi index 6fa0084f6540..485bb462da9e 100644 --- a/stubs/fpdf2/fpdf/fonts.pyi +++ b/stubs/fpdf2/fpdf/fonts.pyi @@ -26,7 +26,7 @@ class FontFace: replace = dataclasses.replace -class FontMixin: +class _FontMixin: i: int type: str name: str @@ -37,11 +37,11 @@ class FontMixin: emphasis: TextEmphasis def encode_text(self, text: str): ... -class CoreFont(FontMixin): +class CoreFont(_FontMixin): def __init__(self, fpdf, fontkey: str, style: int) -> None: ... def get_text_width(self, text: str, font_size_pt: int, _): ... -class TTFFont(FontMixin): +class TTFFont(_FontMixin): ttffile: Incomplete ttfont: Incomplete scale: Incomplete From 434af4a33e2492097b691ae020c28c19604d3941 Mon Sep 17 00:00:00 2001 From: Matthias Schoettle Date: Wed, 1 Nov 2023 21:31:26 -0400 Subject: [PATCH 11/17] update encryption stubs --- stubs/fpdf2/fpdf/encryption.pyi | 41 ++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/stubs/fpdf2/fpdf/encryption.pyi b/stubs/fpdf2/fpdf/encryption.pyi index 45349dae5802..5d14c5a7d514 100644 --- a/stubs/fpdf2/fpdf/encryption.pyi +++ b/stubs/fpdf2/fpdf/encryption.pyi @@ -4,7 +4,7 @@ from logging import Logger from typing import ClassVar, Protocol, TypeVar from typing_extensions import TypeAlias -from .enums import EncryptionMethod +from .enums import AccessPermission, EncryptionMethod from .fpdf import FPDF from .syntax import Name, PDFObject @@ -28,7 +28,7 @@ class CryptFilter: type: Name c_f_m: Name length: int - def __init__(self, mode, length) -> None: ... + def __init__(self, mode: str, length: int) -> None: ... def serialize(self) -> str: ... class EncryptionDictionary(PDFObject): @@ -54,8 +54,8 @@ class StandardSecurityHandler: encryption_method: EncryptionMethod | None cf: CryptFilter | None key_length: int - v: int - r: int + version: int + revision: int encrypt_metadata: bool # The following fields are only defined after a call to generate_passwords(). @@ -64,29 +64,44 @@ class StandardSecurityHandler: o: str k: str u: str + # The following fields are only defined after a call to generate_user_password_rev6(). + ue: Incomplete + # The following fields are only defined after a call to generate_owner_password_rev6(). + oe: Incomplete + # The following fields are only defined after a call to generate_perms_rev6(). + perms_rev6: Incomplete def __init__( self, fpdf: FPDF, owner_password: str, user_password: str | None = None, - permission: Incomplete | None = None, - encryption_method: EncryptionMethod | None = None, + permission: AccessPermission = ..., + encryption_method: EncryptionMethod = ..., encrypt_metadata: bool = False, ) -> None: ... - def generate_passwords(self, file_id) -> None: ... + def generate_passwords(self, file_id: str) -> None: ... def get_encryption_obj(self) -> EncryptionDictionary: ... - def encrypt(self, text: str | bytes | bytearray, obj_id) -> bytes: ... - def encrypt_string(self, string, obj_id): ... - def encrypt_stream(self, stream, obj_id): ... + def encrypt(self, text: str | bytes | bytearray, obj_id: int) -> str | bytes: ... + def encrypt_string(self, string: str, obj_id: int) -> str: ... + def encrypt_stream(self, stream: bytes, obj_id: int) -> bytes: ... def is_aes_algorithm(self) -> bool: ... - def encrypt_bytes(self, data, obj_id) -> list[int]: ... - def encrypt_AES_cryptography(self, key, data): ... + def encrypt_bytes(self, data: bytes, obj_id: int) -> list[int]: ... + def encrypt_AES_cryptography(self, key: bytes, data: bytes) -> bytes: ... def get_initialization_vector(self, size: int) -> bytearray: ... + @classmethod + def get_random_bytes(cls, size: int) -> bytes: ... + @classmethod + def prepare_string(cls, string: str) -> bytes: ... def padded_password(self, password: str) -> bytearray: ... def generate_owner_password(self) -> str: ... def generate_user_password(self) -> str: ... + @classmethod + def compute_hash(cls, input_password: bytes, salt: bytes, user_key: bytes = ...) -> bytes: ... + def generate_user_password_rev6(self) -> None: ... + def generate_owner_password_rev6(self) -> None: ... + def generate_perms_rev6(self) -> None: ... def generate_encryption_key(self) -> bytes: ... -def md5(data: bytes) -> bytes: ... +def md5(data: bytes | bytearray) -> bytes: ... def int32(n: int) -> int: ... From 071beebe7ae9794b23cb70e5cedf3a0a3980cca7 Mon Sep 17 00:00:00 2001 From: Matthias Schoettle Date: Wed, 1 Nov 2023 21:51:01 -0400 Subject: [PATCH 12/17] fixes --- stubs/fpdf2/fpdf/encryption.pyi | 1 - stubs/fpdf2/fpdf/fonts.pyi | 2 ++ stubs/fpdf2/fpdf/line_break.pyi | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/stubs/fpdf2/fpdf/encryption.pyi b/stubs/fpdf2/fpdf/encryption.pyi index 5d14c5a7d514..a37909845c07 100644 --- a/stubs/fpdf2/fpdf/encryption.pyi +++ b/stubs/fpdf2/fpdf/encryption.pyi @@ -88,7 +88,6 @@ class StandardSecurityHandler: def is_aes_algorithm(self) -> bool: ... def encrypt_bytes(self, data: bytes, obj_id: int) -> list[int]: ... def encrypt_AES_cryptography(self, key: bytes, data: bytes) -> bytes: ... - def get_initialization_vector(self, size: int) -> bytearray: ... @classmethod def get_random_bytes(cls, size: int) -> bytes: ... @classmethod diff --git a/stubs/fpdf2/fpdf/fonts.pyi b/stubs/fpdf2/fpdf/fonts.pyi index 485bb462da9e..4339879836a5 100644 --- a/stubs/fpdf2/fpdf/fonts.pyi +++ b/stubs/fpdf2/fpdf/fonts.pyi @@ -83,6 +83,8 @@ class Glyph: def __le__(self, other): ... def __ge__(self, other): ... + __match_args__ = ("glyph_id", "unicode", "glyph_name", "glyph_width") + class SubsetMap: font: TTFFont def __init__(self, font: TTFFont, identities: list[int]) -> None: ... diff --git a/stubs/fpdf2/fpdf/line_break.pyi b/stubs/fpdf2/fpdf/line_break.pyi index 0aed91eaaf67..d35b97fcf8a0 100644 --- a/stubs/fpdf2/fpdf/line_break.pyi +++ b/stubs/fpdf2/fpdf/line_break.pyi @@ -111,7 +111,7 @@ class CurrentLine: number_of_spaces: int space_break_hint: Incomplete hyphen_break_hint: Incomplete - def __init__(self, print_sh: bool = False) -> None: ... + def __init__(self, max_width: float, print_sh: bool = False) -> None: ... def add_character( self, character: str, @@ -142,7 +142,7 @@ class MultiLineBreak: idx_last_forced_break: int | None def __init__( self, - ragments: Sequence[Fragment], + fragments: Sequence[Fragment], max_width: float | Callable[[float], float], margins: Sequence[float], align: Align = ..., From e0899aa8253c11f5c64a161e56c929e31f32a84d Mon Sep 17 00:00:00 2001 From: Matthias Schoettle Date: Fri, 3 Nov 2023 15:37:55 -0400 Subject: [PATCH 13/17] Apply suggestions --- stubs/fpdf2/fpdf/encryption.pyi | 13 ++++++++----- stubs/fpdf2/fpdf/fonts.pyi | 2 +- stubs/fpdf2/fpdf/line_break.pyi | 18 ++++-------------- stubs/fpdf2/fpdf/util.pyi | 8 ++++---- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/stubs/fpdf2/fpdf/encryption.pyi b/stubs/fpdf2/fpdf/encryption.pyi index a37909845c07..38bf0a339af6 100644 --- a/stubs/fpdf2/fpdf/encryption.pyi +++ b/stubs/fpdf2/fpdf/encryption.pyi @@ -1,7 +1,7 @@ from _typeshed import Incomplete, SupportsLenAndGetItem from collections.abc import Generator, Iterable from logging import Logger -from typing import ClassVar, Protocol, TypeVar +from typing import ClassVar, Protocol, TypeVar, overload from typing_extensions import TypeAlias from .enums import AccessPermission, EncryptionMethod @@ -64,11 +64,11 @@ class StandardSecurityHandler: o: str k: str u: str - # The following fields are only defined after a call to generate_user_password_rev6(). + # The following field is only defined after a call to generate_user_password_rev6(). ue: Incomplete - # The following fields are only defined after a call to generate_owner_password_rev6(). + # The following field is only defined after a call to generate_owner_password_rev6(). oe: Incomplete - # The following fields are only defined after a call to generate_perms_rev6(). + # The following field is only defined after a call to generate_perms_rev6(). perms_rev6: Incomplete def __init__( @@ -82,7 +82,10 @@ class StandardSecurityHandler: ) -> None: ... def generate_passwords(self, file_id: str) -> None: ... def get_encryption_obj(self) -> EncryptionDictionary: ... - def encrypt(self, text: str | bytes | bytearray, obj_id: int) -> str | bytes: ... + @overload + def encrypt(self, text: bytes | bytearray, obj_id: int) -> bytes: ... + @overload + def encrypt(self, text: str, obj_id: int) -> str: ... def encrypt_string(self, string: str, obj_id: int) -> str: ... def encrypt_stream(self, stream: bytes, obj_id: int) -> bytes: ... def is_aes_algorithm(self) -> bool: ... diff --git a/stubs/fpdf2/fpdf/fonts.pyi b/stubs/fpdf2/fpdf/fonts.pyi index 4339879836a5..b99629adb54c 100644 --- a/stubs/fpdf2/fpdf/fonts.pyi +++ b/stubs/fpdf2/fpdf/fonts.pyi @@ -73,7 +73,7 @@ class PDFFontDescriptor(PDFObject): class Glyph: glyph_id: int - unicode: tuple[Incomplete] + unicode: tuple[Incomplete, ...] glyph_name: str glyph_width: int def __hash__(self): ... diff --git a/stubs/fpdf2/fpdf/line_break.pyi b/stubs/fpdf2/fpdf/line_break.pyi index d35b97fcf8a0..1840ba1a2cd0 100644 --- a/stubs/fpdf2/fpdf/line_break.pyi +++ b/stubs/fpdf2/fpdf/line_break.pyi @@ -58,20 +58,10 @@ class Fragment: def __eq__(self, other: Fragment) -> bool: ... # type: ignore[override] def get_width(self, start: int = 0, end: int | None = None, chars: str | None = None, initial_cs: bool = True): ... def get_character_width(self, character: str, print_sh: bool = False, initial_cs: bool = True): ... - def render_pdf_text( - self, - frag_ws: Incomplete, - current_ws: Incomplete, - word_spacing: Incomplete, - adjust_x: Incomplete, - adjust_y: Incomplete, - h: Incomplete, - ): ... - def render_pdf_text_ttf(self, frag_ws: Incomplete, word_spacing: Incomplete): ... - def render_with_text_shaping( - self, pos_x: Incomplete, pos_y: Incomplete, h: Incomplete, word_spacing: Incomplete, text_shaping_parms: Incomplete - ): ... - def render_pdf_text_core(self, frag_ws: Incomplete, current_ws: Incomplete): ... + def render_pdf_text(self, frag_ws, current_ws, word_spacing, adjust_x, adjust_y, h): ... + def render_pdf_text_ttf(self, frag_ws, word_spacing): ... + def render_with_text_shaping(self, pos_x, pos_y, h, word_spacing, text_shaping_parms): ... + def render_pdf_text_core(self, frag_ws, current_ws): ... class TextLine(NamedTuple): fragments: tuple[Incomplete, ...] diff --git a/stubs/fpdf2/fpdf/util.pyi b/stubs/fpdf2/fpdf/util.pyi index ab80b8abdffe..9caaff1f0c7d 100644 --- a/stubs/fpdf2/fpdf/util.pyi +++ b/stubs/fpdf2/fpdf/util.pyi @@ -8,10 +8,10 @@ PIL_MEM_BLOCK_SIZE_IN_MIB: Final = 16 class Padding(NamedTuple): # TODO: replaced Number with float - top: float = ... - right: float = ... - bottom: float = ... - left: float = ... + top: float + right: float + bottom: float + left: float @classmethod def new(cls, padding: float | tuple[float, ...] | list[float]): ... From 90507854cc63491a1762cb46b6d9664c4f9ee624 Mon Sep 17 00:00:00 2001 From: Matthias Schoettle Date: Fri, 3 Nov 2023 15:49:39 -0400 Subject: [PATCH 14/17] switch back to Number --- stubs/fpdf2/fpdf/util.pyi | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/stubs/fpdf2/fpdf/util.pyi b/stubs/fpdf2/fpdf/util.pyi index 9caaff1f0c7d..2ff98b28aa77 100644 --- a/stubs/fpdf2/fpdf/util.pyi +++ b/stubs/fpdf2/fpdf/util.pyi @@ -1,4 +1,5 @@ from collections.abc import Iterable +from numbers import Number from typing import Any, AnyStr, NamedTuple from typing_extensions import Final, Literal, TypeAlias @@ -7,29 +8,26 @@ _Unit: TypeAlias = Literal["pt", "mm", "cm", "in"] PIL_MEM_BLOCK_SIZE_IN_MIB: Final = 16 class Padding(NamedTuple): - # TODO: replaced Number with float - top: float - right: float - bottom: float - left: float + top: Number = ... + right: Number = ... + bottom: Number = ... + left: Number = ... @classmethod def new(cls, padding: float | tuple[float, ...] | list[float]): ... def buffer_subst(buffer: bytearray, placeholder: str, value: str) -> bytearray: ... def escape_parens(s: AnyStr) -> AnyStr: ... - -# TODO: change float to Number? -def get_scale_factor(unit: _Unit | float) -> float: ... +def get_scale_factor(unit: _Unit | Number) -> float: ... def convert_unit( # to_convert has a recursive type to_convert: float | Iterable[float | Iterable[Any]], - old_unit: str | float, - new_unit: str | float, + old_unit: str | Number, + new_unit: str | Number, ) -> float | tuple[float, ...]: ... def print_mem_usage(prefix: str) -> None: ... def get_mem_usage(prefix: str) -> str: ... def get_process_rss() -> str: ... -def get_process_rss_as_mib() -> float | None: ... +def get_process_rss_as_mib() -> Number | None: ... def get_process_heap_and_stack_sizes() -> tuple[str, str]: ... def get_pymalloc_allocated_over_total_size() -> str: ... def get_gc_managed_objs_total_size() -> str: ... From 176e711fb8336b823575dd18f04828218c561432 Mon Sep 17 00:00:00 2001 From: Matthias Schoettle Date: Fri, 3 Nov 2023 15:54:14 -0400 Subject: [PATCH 15/17] fix Padding --- stubs/fpdf2/fpdf/util.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stubs/fpdf2/fpdf/util.pyi b/stubs/fpdf2/fpdf/util.pyi index 2ff98b28aa77..262350ab811c 100644 --- a/stubs/fpdf2/fpdf/util.pyi +++ b/stubs/fpdf2/fpdf/util.pyi @@ -8,10 +8,10 @@ _Unit: TypeAlias = Literal["pt", "mm", "cm", "in"] PIL_MEM_BLOCK_SIZE_IN_MIB: Final = 16 class Padding(NamedTuple): - top: Number = ... - right: Number = ... - bottom: Number = ... - left: Number = ... + top: Number + right: Number + bottom: Number + left: Number @classmethod def new(cls, padding: float | tuple[float, ...] | list[float]): ... From e8dc4c97a26cca4b754bcea0626bd21b4771ace5 Mon Sep 17 00:00:00 2001 From: Matthias Schoettle Date: Fri, 3 Nov 2023 16:03:01 -0400 Subject: [PATCH 16/17] fix Padding --- stubs/fpdf2/fpdf/util.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stubs/fpdf2/fpdf/util.pyi b/stubs/fpdf2/fpdf/util.pyi index 262350ab811c..e8f2320fa0b3 100644 --- a/stubs/fpdf2/fpdf/util.pyi +++ b/stubs/fpdf2/fpdf/util.pyi @@ -8,10 +8,10 @@ _Unit: TypeAlias = Literal["pt", "mm", "cm", "in"] PIL_MEM_BLOCK_SIZE_IN_MIB: Final = 16 class Padding(NamedTuple): - top: Number - right: Number - bottom: Number - left: Number + top: Number = 0 + right: Number = 0 + bottom: Number = 0 + left: Number = 0 @classmethod def new(cls, padding: float | tuple[float, ...] | list[float]): ... From 52761c1012f510ce31a389d9a60501bcc15b855e Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 15 Nov 2023 11:52:46 +0100 Subject: [PATCH 17/17] Use `float` instead of `Number` (again) --- stubs/fpdf2/fpdf/util.pyi | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/stubs/fpdf2/fpdf/util.pyi b/stubs/fpdf2/fpdf/util.pyi index e8f2320fa0b3..63b13b49e79e 100644 --- a/stubs/fpdf2/fpdf/util.pyi +++ b/stubs/fpdf2/fpdf/util.pyi @@ -1,5 +1,4 @@ from collections.abc import Iterable -from numbers import Number from typing import Any, AnyStr, NamedTuple from typing_extensions import Final, Literal, TypeAlias @@ -8,26 +7,26 @@ _Unit: TypeAlias = Literal["pt", "mm", "cm", "in"] PIL_MEM_BLOCK_SIZE_IN_MIB: Final = 16 class Padding(NamedTuple): - top: Number = 0 - right: Number = 0 - bottom: Number = 0 - left: Number = 0 + top: float = 0 + right: float = 0 + bottom: float = 0 + left: float = 0 @classmethod def new(cls, padding: float | tuple[float, ...] | list[float]): ... def buffer_subst(buffer: bytearray, placeholder: str, value: str) -> bytearray: ... def escape_parens(s: AnyStr) -> AnyStr: ... -def get_scale_factor(unit: _Unit | Number) -> float: ... +def get_scale_factor(unit: _Unit | float) -> float: ... def convert_unit( # to_convert has a recursive type to_convert: float | Iterable[float | Iterable[Any]], - old_unit: str | Number, - new_unit: str | Number, + old_unit: str | float, + new_unit: str | float, ) -> float | tuple[float, ...]: ... def print_mem_usage(prefix: str) -> None: ... def get_mem_usage(prefix: str) -> str: ... def get_process_rss() -> str: ... -def get_process_rss_as_mib() -> Number | None: ... +def get_process_rss_as_mib() -> float | None: ... def get_process_heap_and_stack_sizes() -> tuple[str, str]: ... def get_pymalloc_allocated_over_total_size() -> str: ... def get_gc_managed_objs_total_size() -> str: ...