Skip to content

Commit 10086c0

Browse files
authored
Fix Any subclassing in fpdf2 (#9536)
1 parent 372073d commit 10086c0

File tree

3 files changed

+62
-6
lines changed

3 files changed

+62
-6
lines changed

stubs/fpdf2/@tests/stubtest_allowlist.txt

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ fpdf.fpdf.FPDF.output
66
fpdf.FPDF.set_creation_date
77
fpdf.fpdf.FPDF.set_creation_date
88

9+
# fonttools shims since we can't import it
10+
fpdf._fonttools_shims
11+
912
# Checking the following function crashes stubtest 0.991, but seems to be
1013
# fixed in later versions.
1114
fpdf.FPDF.set_encryption

stubs/fpdf2/fpdf/_fonttools_shims.pyi

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# from fontTools.misc.loggingTools
2+
from abc import ABCMeta, abstractmethod
3+
from collections.abc import Mapping
4+
from logging import Logger
5+
from typing import Protocol
6+
from typing_extensions import TypeAlias
7+
8+
# from fonttools.ttLib.ttGlyphSet
9+
class _TTGlyph(Protocol):
10+
def __init__(self, glyphSet: _TTGlyphSet, glyphName: str) -> None: ...
11+
def draw(self, pen) -> None: ...
12+
def drawPoints(self, pen) -> None: ...
13+
14+
_TTGlyphSet: TypeAlias = Mapping[str, _TTGlyph] # Simplified for our needs
15+
16+
# from fontTools.misc.loggingTools
17+
18+
class LogMixin:
19+
@property
20+
def log(self) -> Logger: ...
21+
22+
# from fontTools.pens.basePen
23+
class AbstractPen:
24+
@abstractmethod
25+
def moveTo(self, pt: tuple[float, float]) -> None: ...
26+
@abstractmethod
27+
def lineTo(self, pt: tuple[float, float]) -> None: ...
28+
@abstractmethod
29+
def curveTo(self, *points: tuple[float, float]) -> None: ...
30+
@abstractmethod
31+
def qCurveTo(self, *points: tuple[float, float]) -> None: ...
32+
def closePath(self) -> None: ...
33+
def endPath(self) -> None: ...
34+
@abstractmethod
35+
def addComponent(self, glyphName: str, transformation: tuple[float, float, float, float, float, float]) -> None: ...
36+
37+
class LoggingPen(LogMixin, AbstractPen, metaclass=ABCMeta): ...
38+
39+
class DecomposingPen(LoggingPen, metaclass=ABCMeta):
40+
skipMissingComponents: bool
41+
glyphSet: _TTGlyphSet | None
42+
def __init__(self, glyphSet: _TTGlyphSet | None) -> None: ...
43+
def addComponent(self, glyphName: str, transformation: tuple[float, float, float, float, float, float]) -> None: ...
44+
45+
class BasePen(DecomposingPen):
46+
def __init__(self, glyphSet: _TTGlyphSet | None = ...) -> None: ...
47+
def closePath(self) -> None: ...
48+
def endPath(self) -> None: ...
49+
def moveTo(self, pt: tuple[float, float]) -> None: ...
50+
def lineTo(self, pt: tuple[float, float]) -> None: ...
51+
def curveTo(self, *points: tuple[float, float]) -> None: ...
52+
def qCurveTo(self, *points: tuple[float, float]) -> None: ...

stubs/fpdf2/fpdf/svg.pyi

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from _typeshed import Incomplete
22
from collections.abc import Callable
33
from re import Pattern
4-
from typing_extensions import TypeAlias
54

6-
_BasePen: TypeAlias = Incomplete # actually fontTools.pens.basePen.BasePen
5+
from fpdf.drawing import PaintedPath
6+
7+
from ._fonttools_shims import BasePen, _TTGlyphSet
78

89
__pdoc__: dict[str, bool]
910

@@ -56,14 +57,14 @@ class ShapeBuilder:
5657

5758
def convert_transforms(tfstr): ...
5859

59-
class PathPen(_BasePen):
60-
pdf_path: Incomplete
60+
class PathPen(BasePen):
61+
pdf_path: PaintedPath
6162
last_was_line_to: bool
6263
first_is_move: bool | None
63-
def __init__(self, pdf_path, *args, **kwargs): ...
64+
def __init__(self, pdf_path: PaintedPath, glyphSet: _TTGlyphSet | None = ...): ...
6465
def arcTo(self, rx, ry, rotation, arc, sweep, end) -> None: ...
6566

66-
def svg_path_converter(pdf_path, svg_path) -> None: ...
67+
def svg_path_converter(pdf_path: PaintedPath, svg_path: str) -> None: ...
6768

6869
class SVGObject:
6970
@classmethod

0 commit comments

Comments
 (0)