Skip to content

Commit

Permalink
be more precise about types on ps/pdf stacks, remove most of the Any …
Browse files Browse the repository at this point in the history
…annotations
  • Loading branch information
0xabu committed Aug 22, 2021
1 parent be15501 commit ff787a9
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 116 deletions.
3 changes: 2 additions & 1 deletion pdfminer/cmapdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ def get_unicode_map(cls, name: str, vertical: bool = False) -> UnicodeMap:
return cls._umap_cache[name][vertical]


class CMapParser(PSStackParser):
# int here means that we're not extending PSStackParser with additional types.
class CMapParser(PSStackParser[int]):

def __init__(self, cmap, fp):
PSStackParser.__init__(self, fp)
Expand Down
7 changes: 4 additions & 3 deletions pdfminer/converter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io
import logging
from pdfminer.pdfcolor import PDFColorSpace
from typing import Any, List, Optional, Sequence
from typing import Any, List, Optional, Sequence, cast
import re
import sys

Expand All @@ -27,7 +27,7 @@
from .pdfinterp import PDFGraphicState, PDFResourceManager
from .pdfpage import PDFPage
from .pdftypes import PDFStream
from .utils import Matrix, Rect, PathSegment
from .utils import Point, Matrix, Rect, PathSegment
from .utils import apply_matrix_pt
from .utils import bbox2str
from .utils import enc
Expand Down Expand Up @@ -104,7 +104,8 @@ def paint_path(self, gstate: PDFGraphicState, stroke: bool, fill: bool,
# And, per Section 4.4's Table 4.9, all other path commands place
# their point-position in their final two arguments. (Any preceding
# arguments represent control points on Bézier curves.)
raw_pts = [p[-2:] if p[0] != 'h' else path[0][-2:] for p in path]
raw_pts = [cast(Point, p[-2:] if p[0] != 'h' else path[0][-2:])
for p in path]
pts = [apply_matrix_pt(self.ctm, pt) for pt in raw_pts]

if shape in {'mlh', 'ml'}:
Expand Down
6 changes: 3 additions & 3 deletions pdfminer/pdfdevice.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import (Any, BinaryIO, Iterable, List, Optional, Sequence, Tuple,
from typing import (Any, BinaryIO, Iterable, List, Optional, Sequence,
TYPE_CHECKING)
from . import utils
from .utils import Matrix, Point, Rect
from .utils import Matrix, Point, Rect, PathSegment
from .pdfcolor import PDFColorSpace
from .pdffont import PDFFont
from .pdffont import PDFUnicodeNotDefined
Expand Down Expand Up @@ -62,7 +62,7 @@ def end_figure(self, name: str) -> None:

def paint_path(self, graphicstate: "PDFGraphicState", stroke: bool,
fill: bool, evenodd: bool,
path: Sequence[Tuple[str, float, float]]) -> None:
path: Sequence[PathSegment]) -> None:
return

def render_image(self, name: str, stream: PDFStream) -> None:
Expand Down
3 changes: 2 additions & 1 deletion pdfminer/pdffont.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def get_metrics(cls, fontname):
return FONT_METRICS[fontname]


class Type1FontHeaderParser(PSStackParser):
# int here means that we're not extending PSStackParser with additional types.
class Type1FontHeaderParser(PSStackParser[int]):

KEYWORD_BEGIN = KWD(b'begin')
KEYWORD_END = KWD(b'end')
Expand Down

0 comments on commit ff787a9

Please sign in to comment.