Skip to content

Commit

Permalink
add missing None return type to all __init__ methods
Browse files Browse the repository at this point in the history
  • Loading branch information
0xabu committed Sep 6, 2021
1 parent c0d62d6 commit feb031b
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 64 deletions.
2 changes: 1 addition & 1 deletion pdfminer/arcfour.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Arcfour:

def __init__(self, key: Sequence[int]):
def __init__(self, key: Sequence[int]) -> None:
# because Py3 range is not indexable
s = [i for i in range(256)]
j = 0
Expand Down
6 changes: 3 additions & 3 deletions pdfminer/ccitt.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class ByteSkip(Exception):

_color: int

def __init__(self, width: int, bytealign: bool = False):
def __init__(self, width: int, bytealign: bool = False) -> None:
BitParser.__init__(self)
self.width = width
self.bytealign = bytealign
Expand Down Expand Up @@ -541,7 +541,7 @@ def _do_uncompressed(self, bits: str) -> None:
class CCITTFaxDecoder(CCITTG4Parser):

def __init__(self, width: int, bytealign: bool = False,
reversed: bool = False):
reversed: bool = False) -> None:
CCITTG4Parser.__init__(self, width, bytealign=bytealign)
self.reversed = reversed
self._buf = b''
Expand Down Expand Up @@ -582,7 +582,7 @@ def main(argv: List[str]) -> None:
return

class Parser(CCITTG4Parser):
def __init__(self, width: int, bytealign: bool = False):
def __init__(self, width: int, bytealign: bool = False) -> None:
import pygame # type: ignore[import]
CCITTG4Parser.__init__(self, width, bytealign=bytealign)
self.img = pygame.Surface((self.width, 1000))
Expand Down
12 changes: 6 additions & 6 deletions pdfminer/cmapdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CMapBase:

debug = 0

def __init__(self, **kwargs: object):
def __init__(self, **kwargs: object) -> None:
self.attrs: MutableMapping[str, object] = kwargs.copy()
return

Expand All @@ -68,7 +68,7 @@ def decode(self, code: bytes) -> Iterable[int]:

class CMap(CMapBase):

def __init__(self, **kwargs: Union[str, int]):
def __init__(self, **kwargs: Union[str, int]) -> None:
CMapBase.__init__(self, **kwargs)
self.code2cid: Dict[int, object] = {}
return
Expand Down Expand Up @@ -142,7 +142,7 @@ def decode(self, code: bytes) -> Tuple[int, ...]:

class UnicodeMap(CMapBase):

def __init__(self, **kwargs: Union[str, int]):
def __init__(self, **kwargs: Union[str, int]) -> None:
CMapBase.__init__(self, **kwargs)
self.cid2unichr: Dict[int, str] = {}
return
Expand Down Expand Up @@ -200,7 +200,7 @@ def add_cid2unichr(self, cid: int, code: Union[PSLiteral, bytes, int]

class PyCMap(CMap):

def __init__(self, name: str, module: Any):
def __init__(self, name: str, module: Any) -> None:
super().__init__(CMapName=name)
self.code2cid = module.CODE2CID
if module.IS_VERTICAL:
Expand All @@ -210,7 +210,7 @@ def __init__(self, name: str, module: Any):

class PyUnicodeMap(UnicodeMap):

def __init__(self, name: str, module: Any, vertical: bool):
def __init__(self, name: str, module: Any, vertical: bool) -> None:
super().__init__(CMapName=name)
if vertical:
self.cid2unichr = module.CID2UNICHR_V
Expand Down Expand Up @@ -278,7 +278,7 @@ def get_unicode_map(cls, name: str, vertical: bool = False) -> UnicodeMap:

class CMapParser(PSStackParser[PSKeyword]):

def __init__(self, cmap: CMapBase, fp: BinaryIO):
def __init__(self, cmap: CMapBase, fp: BinaryIO) -> None:
PSStackParser.__init__(self, fp)
self.cmap = cmap
# some ToUnicode maps don't have "begincmap" keyword.
Expand Down
12 changes: 6 additions & 6 deletions pdfminer/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PDFLayoutAnalyzer(PDFTextDevice):
ctm: Matrix

def __init__(self, rsrcmgr: PDFResourceManager, pageno: int = 1,
laparams: Optional[LAParams] = None):
laparams: Optional[LAParams] = None) -> None:
PDFTextDevice.__init__(self, rsrcmgr)
self.pageno = pageno
self.laparams = laparams
Expand Down Expand Up @@ -167,7 +167,7 @@ class PDFPageAggregator(PDFLayoutAnalyzer):
def __init__(self,
rsrcmgr: PDFResourceManager,
pageno: int = 1,
laparams: Optional[LAParams] = None):
laparams: Optional[LAParams] = None) -> None:
PDFLayoutAnalyzer.__init__(self, rsrcmgr, pageno=pageno,
laparams=laparams)
self.result: Optional[LTPage] = None
Expand All @@ -192,7 +192,7 @@ def __init__(self,
outfp: IOType,
codec: str = 'utf-8',
pageno: int = 1,
laparams: Optional[LAParams] = None):
laparams: Optional[LAParams] = None) -> None:
PDFLayoutAnalyzer.__init__(self, rsrcmgr, pageno=pageno,
laparams=laparams)
self.outfp: IOType = outfp
Expand Down Expand Up @@ -223,7 +223,7 @@ def __init__(self,
pageno: int = 1,
laparams: Optional[LAParams] = None,
showpageno: bool = False,
imagewriter: Optional[ImageWriter] = None):
imagewriter: Optional[ImageWriter] = None) -> None:
super().__init__(rsrcmgr, outfp, codec=codec, pageno=pageno,
laparams=laparams)
self.showpageno = showpageno
Expand Down Expand Up @@ -299,7 +299,7 @@ def __init__(self,
imagewriter: Optional[ImageWriter] = None,
debug: int = 0,
rect_colors: Optional[Dict[str, str]] = None,
text_colors: Optional[Dict[str, str]] = None):
text_colors: Optional[Dict[str, str]] = None) -> None:
PDFConverter.__init__(self, rsrcmgr, outfp, codec=codec, pageno=pageno,
laparams=laparams)

Expand Down Expand Up @@ -530,7 +530,7 @@ def __init__(self,
pageno: int = 1,
laparams: Optional[LAParams] = None,
imagewriter: Optional[ImageWriter] = None,
stripcontrol: bool = False):
stripcontrol: bool = False) -> None:
PDFConverter.__init__(self, rsrcmgr, outfp, codec=codec, pageno=pageno,
laparams=laparams)

Expand Down
5 changes: 3 additions & 2 deletions pdfminer/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def align32(x: int) -> int:


class BMPWriter:
def __init__(self, fp: BinaryIO, bits: int, width: int, height: int):
def __init__(self, fp: BinaryIO, bits: int, width: int, height: int
) -> None:
self.fp = fp
self.bits = bits
self.width = width
Expand Down Expand Up @@ -65,7 +66,7 @@ class ImageWriter:
Supports various image types: JPEG, JBIG2 and bitmaps
"""

def __init__(self, outdir: str):
def __init__(self, outdir: str) -> None:
self.outdir = outdir
if not os.path.exists(self.outdir):
os.makedirs(self.outdir)
Expand Down
34 changes: 17 additions & 17 deletions pdfminer/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

class IndexAssigner:

def __init__(self, index: int = 0):
def __init__(self, index: int = 0) -> None:
self.index = index
return

Expand Down Expand Up @@ -75,7 +75,7 @@ def __init__(self,
word_margin: float = 0.1,
boxes_flow: Optional[float] = 0.5,
detect_vertical: bool = False,
all_texts: bool = False):
all_texts: bool = False) -> None:
self.line_overlap = line_overlap
self.char_margin = char_margin
self.line_margin = line_margin
Expand Down Expand Up @@ -127,7 +127,7 @@ def get_text(self) -> str:
class LTComponent(LTItem):
"""Object with a bounding box"""

def __init__(self, bbox: Rect):
def __init__(self, bbox: Rect) -> None:
LTItem.__init__(self)
self.set_bbox(bbox)
return
Expand Down Expand Up @@ -206,7 +206,7 @@ class LTCurve(LTComponent):
def __init__(self, linewidth: float, pts: List[Point],
stroke: bool = False, fill: bool = False,
evenodd: bool = False, stroking_color: Optional[Color] = None,
non_stroking_color: Optional[Color] = None):
non_stroking_color: Optional[Color] = None) -> None:
LTComponent.__init__(self, get_bound(pts))
self.pts = pts
self.linewidth = linewidth
Expand All @@ -230,7 +230,7 @@ class LTLine(LTCurve):
def __init__(self, linewidth: float, p0: Point, p1: Point,
stroke: bool = False, fill: bool = False,
evenodd: bool = False, stroking_color: Optional[Color] = None,
non_stroking_color: Optional[Color] = None):
non_stroking_color: Optional[Color] = None) -> None:
LTCurve.__init__(self, linewidth, [p0, p1], stroke, fill, evenodd,
stroking_color, non_stroking_color)
return
Expand All @@ -245,7 +245,7 @@ class LTRect(LTCurve):
def __init__(self, linewidth: float, bbox: Rect,
stroke: bool = False, fill: bool = False,
evenodd: bool = False, stroking_color: Optional[Color] = None,
non_stroking_color: Optional[Color] = None):
non_stroking_color: Optional[Color] = None) -> None:
(x0, y0, x1, y1) = bbox
LTCurve.__init__(self, linewidth,
[(x0, y0), (x1, y0), (x1, y1), (x0, y1)], stroke,
Expand All @@ -259,7 +259,7 @@ class LTImage(LTComponent):
Embedded images can be in JPEG, Bitmap or JBIG2.
"""

def __init__(self, name: str, stream: PDFStream, bbox: Rect):
def __init__(self, name: str, stream: PDFStream, bbox: Rect) -> None:
LTComponent.__init__(self, bbox)
self.name = name
self.stream = stream
Expand All @@ -286,7 +286,7 @@ class LTAnno(LTItem, LTText):
according to the relationship between two characters (e.g. a space).
"""

def __init__(self, text: str):
def __init__(self, text: str) -> None:
self._text = text
return

Expand All @@ -300,7 +300,7 @@ class LTChar(LTComponent, LTText):
def __init__(self, matrix: Matrix, font: PDFFont, fontsize: float,
scaling: float, rise: float, text: str, textwidth: float,
textdisp: Union[float, Tuple[Optional[float], float]],
ncs: PDFColorSpace, graphicstate: PDFGraphicState):
ncs: PDFColorSpace, graphicstate: PDFGraphicState) -> None:
LTText.__init__(self)
self._text = text
self.matrix = matrix
Expand Down Expand Up @@ -360,7 +360,7 @@ def is_compatible(self, obj: object) -> bool:
class LTContainer(LTComponent, Generic[LTItemT]):
"""Object that can be extended and analyzed"""

def __init__(self, bbox: Rect):
def __init__(self, bbox: Rect) -> None:
LTComponent.__init__(self, bbox)
self._objs: List[LTItemT] = []
return
Expand Down Expand Up @@ -421,7 +421,7 @@ class LTTextLine(LTTextContainer[TextLineElement]):
the text's writing mode.
"""

def __init__(self, word_margin: float):
def __init__(self, word_margin: float) -> None:
super().__init__()
self.word_margin = word_margin
return
Expand All @@ -442,7 +442,7 @@ def find_neighbors(self, plane: Plane[LTComponentT], ratio: float


class LTTextLineHorizontal(LTTextLine):
def __init__(self, word_margin: float):
def __init__(self, word_margin: float) -> None:
LTTextLine.__init__(self, word_margin)
self._x1: float = +INF
return
Expand Down Expand Up @@ -505,7 +505,7 @@ def _is_same_height_as(self, other: LTComponent, tolerance: float = 0


class LTTextLineVertical(LTTextLine):
def __init__(self, word_margin: float):
def __init__(self, word_margin: float) -> None:
LTTextLine.__init__(self, word_margin)
self._y0: float = -INF
return
Expand Down Expand Up @@ -612,7 +612,7 @@ def get_writing_mode(self) -> str:


class LTTextGroup(LTTextContainer[TextGroupElement]):
def __init__(self, objs: Iterable[TextGroupElement]):
def __init__(self, objs: Iterable[TextGroupElement]) -> None:
super().__init__()
self.extend(objs)
return
Expand Down Expand Up @@ -643,7 +643,7 @@ def analyze(self, laparams: LAParams) -> None:


class LTLayoutContainer(LTContainer[LTComponent]):
def __init__(self, bbox: Rect):
def __init__(self, bbox: Rect) -> None:
LTContainer.__init__(self, bbox)
self.groups: Optional[List[LTTextGroup]] = None
return
Expand Down Expand Up @@ -886,7 +886,7 @@ class LTFigure(LTLayoutContainer):
recursively.
"""

def __init__(self, name: str, bbox: Rect, matrix: Matrix):
def __init__(self, name: str, bbox: Rect, matrix: Matrix) -> None:
self.name = name
self.matrix = matrix
(x, y, w, h) = bbox
Expand Down Expand Up @@ -914,7 +914,7 @@ class LTPage(LTLayoutContainer):
LTCurve and LTLine.
"""

def __init__(self, pageid: int, bbox: Rect, rotate: float = 0):
def __init__(self, pageid: int, bbox: Rect, rotate: float = 0) -> None:
LTLayoutContainer.__init__(self, bbox)
self.pageid = pageid
self.rotate = rotate
Expand Down
2 changes: 1 addition & 1 deletion pdfminer/lzw.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CorruptDataError(Exception):

class LZWDecoder:

def __init__(self, fp: BinaryIO):
def __init__(self, fp: BinaryIO) -> None:
self.fp = fp
self.buff = 0
self.bpos = 8
Expand Down
2 changes: 1 addition & 1 deletion pdfminer/pdfcolor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class PDFColorSpace:

def __init__(self, name: str, ncomponents: int):
def __init__(self, name: str, ncomponents: int) -> None:
self.name = name
self.ncomponents = ncomponents
return
Expand Down
4 changes: 2 additions & 2 deletions pdfminer/pdfdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PDFDevice:
"""Translate the output of PDFPageInterpreter to the output that is needed
"""

def __init__(self, rsrcmgr: "PDFResourceManager"):
def __init__(self, rsrcmgr: "PDFResourceManager") -> None:
self.rsrcmgr = rsrcmgr
self.ctm: Optional[Matrix] = None
return
Expand Down Expand Up @@ -168,7 +168,7 @@ def render_char(self, matrix: Matrix, font: PDFFont, fontsize: float,
class TagExtractor(PDFDevice):

def __init__(self, rsrcmgr: "PDFResourceManager", outfp: BinaryIO,
codec: str = 'utf-8'):
codec: str = 'utf-8') -> None:
PDFDevice.__init__(self, rsrcmgr)
self.outfp = outfp
self.codec = codec
Expand Down
4 changes: 2 additions & 2 deletions pdfminer/pdfdocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class PDFStandardSecurityHandler:
supported_revisions: Tuple[int, ...] = (2, 3)

def __init__(self, docid: Sequence[bytes], param: Dict[str, Any],
password: str = ''):
password: str = '') -> None:
self.docid = docid
self.param = param
self.password = password
Expand Down Expand Up @@ -576,7 +576,7 @@ class PDFDocument:
}

def __init__(self, parser: PDFParser, password: str = '',
caching: bool = True, fallback: bool = True):
caching: bool = True, fallback: bool = True) -> None:
"Set the document to use a given PDFParser object."
self.caching = caching
self.xrefs: List[PDFBaseXRef] = []
Expand Down
Loading

0 comments on commit feb031b

Please sign in to comment.