Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove obsolete returns #707

Merged
merged 4 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed
- Replace warnings.warn with logging.Logger.warning in line with [recommended use](https://docs.python.org/3/howto/logging.html#when-to-use-logging) ([#673](https://github.com/pdfminer/pdfminer.six/pull/673))

### Removed
- Unnecessary return statements without argument at the end of functions ([#707](https://github.com/pdfminer/pdfminer.six/pull/707))

## [20211012]

### Added
Expand Down
1 change: 0 additions & 1 deletion pdfminer/arcfour.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def __init__(self, key: Sequence[int]) -> None:
(s[i], s[j]) = (s[j], s[i])
self.s = s
(self.i, self.j) = (0, 0)
return

def process(self, data: bytes) -> bytes:
(i, j) = (self.i, self.j)
Expand Down
4 changes: 0 additions & 4 deletions pdfminer/ccitt.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class BitParser:

def __init__(self) -> None:
self._pos = 0
return

@classmethod
def add(cls, root: BitParserState, v: Union[int, str], bits: str) -> None:
Expand All @@ -53,13 +52,11 @@ def add(cls, root: BitParserState, v: Union[int, str], bits: str) -> None:
b = 0
assert b is not None
p[b] = v
return

def feedbytes(self, data: bytes) -> None:
for byte in get_bytes(data):
for m in (128, 64, 32, 16, 8, 4, 2, 1):
self._parse_bit(byte & m)
return

def _parse_bit(self, x: object) -> None:
if x:
Expand All @@ -72,7 +69,6 @@ def _parse_bit(self, x: object) -> None:
else:
assert self._accept is not None
self._state = self._accept(v)
return


class CCITTG4Parser(BitParser):
Expand Down
34 changes: 11 additions & 23 deletions pdfminer/cmapdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@

"""

import sys
import gzip
import logging
import os
import os.path
import gzip
import pickle as pickle
import struct
import logging
import sys
from typing import (Any, BinaryIO, Dict, Iterable, Iterator, List,
MutableMapping, Optional, TextIO, Tuple, Union, cast)
from .psparser import PSStackParser
from .psparser import PSSyntaxError

from .encodingdb import name2unicode
from .psparser import KWD
from .psparser import PSEOF
from .psparser import PSKeyword
from .psparser import PSLiteral
from .psparser import PSStackParser
from .psparser import PSSyntaxError
from .psparser import literal_name
from .psparser import KWD
from .encodingdb import name2unicode
from .utils import choplist
from .utils import nunpack


log = logging.getLogger(__name__)


Expand All @@ -43,24 +43,22 @@ class CMapBase:

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

def is_vertical(self) -> bool:
return self.attrs.get('WMode', 0) != 0

def set_attr(self, k: str, v: object) -> None:
self.attrs[k] = v
return

def add_code2cid(self, code: str, cid: int) -> None:
return
pass

def add_cid2unichr(self, cid: int, code: Union[PSLiteral, bytes, int]
) -> None:
return
pass

def use_cmap(self, cmap: "CMapBase") -> None:
return
pass

def decode(self, code: bytes) -> Iterable[int]:
raise NotImplementedError
Expand All @@ -71,7 +69,6 @@ class CMap(CMapBase):
def __init__(self, **kwargs: Union[str, int]) -> None:
CMapBase.__init__(self, **kwargs)
self.code2cid: Dict[int, object] = {}
return

def __repr__(self) -> str:
return '<CMap: %s>' % self.attrs.get('CMapName')
Expand All @@ -88,7 +85,6 @@ def copy(dst: Dict[int, object], src: Dict[int, object]) -> None:
else:
dst[k] = v
copy(self.code2cid, cmap.code2cid)
return

def decode(self, code: bytes) -> Iterator[int]:
log.debug('decode: %r, %r', self, code)
Expand All @@ -103,7 +99,6 @@ def decode(self, code: bytes) -> Iterator[int]:
d = cast(Dict[int, object], x)
else:
d = self.code2cid
return

def dump(self, out: TextIO = sys.stdout,
code2cid: Optional[Dict[int, object]] = None,
Expand All @@ -117,7 +112,6 @@ def dump(self, out: TextIO = sys.stdout,
out.write('code %r = cid %d\n' % (c, v))
else:
self.dump(out=out, code2cid=cast(Dict[int, object], v), code=c)
return


class IdentityCMap(CMapBase):
Expand Down Expand Up @@ -145,7 +139,6 @@ class UnicodeMap(CMapBase):
def __init__(self, **kwargs: Union[str, int]) -> None:
CMapBase.__init__(self, **kwargs)
self.cid2unichr: Dict[int, str] = {}
return

def __repr__(self) -> str:
return '<UnicodeMap: %s>' % self.attrs.get('CMapName')
Expand All @@ -157,7 +150,6 @@ def get_unichr(self, cid: int) -> str:
def dump(self, out: TextIO = sys.stdout) -> None:
for (k, v) in sorted(self.cid2unichr.items()):
out.write('cid %d = unicode %r\n' % (k, v))
return


class IdentityUnicodeMap(UnicodeMap):
Expand All @@ -183,7 +175,6 @@ def add_code2cid(self, code: str, cid: int) -> None:
d = t
ci = ord(code[-1])
d[ci] = cid
return


class FileUnicodeMap(UnicodeMap):
Expand All @@ -202,7 +193,6 @@ def add_cid2unichr(self, cid: int, code: Union[PSLiteral, bytes, int]
self.cid2unichr[cid] = chr(code)
else:
raise TypeError(code)
return


class PyCMap(CMap):
Expand All @@ -212,7 +202,6 @@ def __init__(self, name: str, module: Any) -> None:
self.code2cid = module.CODE2CID
if module.IS_VERTICAL:
self.attrs['WMode'] = 1
return


class PyUnicodeMap(UnicodeMap):
Expand All @@ -224,7 +213,6 @@ def __init__(self, name: str, module: Any, vertical: bool) -> None:
self.attrs['WMode'] = 1
else:
self.cid2unichr = module.CID2UNICHR_H
return


class CMapDB:
Expand Down
19 changes: 4 additions & 15 deletions pdfminer/converter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import io
import logging
from pdfminer.pdfcolor import PDFColorSpace
import re
from typing import (BinaryIO, Dict, Generic, List, Optional, Sequence, TextIO,
Tuple, TypeVar, Union, cast)
import re

from pdfminer.pdfcolor import PDFColorSpace
from . import utils
from .image import ImageWriter
from .layout import LAParams, LTComponent, TextGroupElement
from .layout import LTChar
from .layout import LTContainer
Expand Down Expand Up @@ -33,7 +34,6 @@
from .utils import bbox2str
from .utils import enc
from .utils import mult_matrix
from .image import ImageWriter

log = logging.getLogger(__name__)

Expand All @@ -52,15 +52,13 @@ def __init__(
self.pageno = pageno
self.laparams = laparams
self._stack: List[LTLayoutContainer] = []
return

def begin_page(self, page: PDFPage, ctm: Matrix) -> None:
(x0, y0, x1, y1) = page.mediabox
(x0, y0) = apply_matrix_pt(ctm, (x0, y0))
(x1, y1) = apply_matrix_pt(ctm, (x1, y1))
mediabox = (0, 0, abs(x0-x1), abs(y0-y1))
self.cur_item = LTPage(self.pageno, mediabox)
return

def end_page(self, page: PDFPage) -> None:
assert not self._stack, str(len(self._stack))
Expand All @@ -69,27 +67,23 @@ def end_page(self, page: PDFPage) -> None:
self.cur_item.analyze(self.laparams)
self.pageno += 1
self.receive_layout(self.cur_item)
return

def begin_figure(self, name: str, bbox: Rect, matrix: Matrix) -> None:
self._stack.append(self.cur_item)
self.cur_item = LTFigure(name, bbox, mult_matrix(matrix, self.ctm))
return

def end_figure(self, _: str) -> None:
fig = self.cur_item
assert isinstance(self.cur_item, LTFigure), str(type(self.cur_item))
self.cur_item = self._stack.pop()
self.cur_item.add(fig)
return

def render_image(self, name: str, stream: PDFStream) -> None:
assert isinstance(self.cur_item, LTFigure), str(type(self.cur_item))
item = LTImage(name, stream,
(self.cur_item.x0, self.cur_item.y0,
self.cur_item.x1, self.cur_item.y1))
self.cur_item.add(item)
return

def paint_path(
self,
Expand Down Expand Up @@ -178,7 +172,7 @@ def handle_undefined_char(self, font: PDFFont, cid: int) -> str:
return '(cid:%d)' % cid

def receive_layout(self, ltpage: LTPage) -> None:
return
pass


class PDFPageAggregator(PDFLayoutAnalyzer):
Expand All @@ -191,11 +185,9 @@ def __init__(
PDFLayoutAnalyzer.__init__(self, rsrcmgr, pageno=pageno,
laparams=laparams)
self.result: Optional[LTPage] = None
return

def receive_layout(self, ltpage: LTPage) -> None:
self.result = ltpage
return

def get_result(self) -> LTPage:
assert self.result is not None
Expand Down Expand Up @@ -254,15 +246,13 @@ def __init__(
laparams=laparams)
self.showpageno = showpageno
self.imagewriter = imagewriter
return

def write_text(self, text: str) -> None:
text = utils.compatible_encode_method(text, self.codec, 'ignore')
if self.outfp_binary:
cast(BinaryIO, self.outfp).write(text.encode())
else:
cast(TextIO, self.outfp).write(text)
return

def receive_layout(self, ltpage: LTPage) -> None:
def render(item: LTItem) -> None:
Expand All @@ -280,7 +270,6 @@ def render(item: LTItem) -> None:
self.write_text('Page %s\n' % ltpage.pageid)
render(ltpage)
self.write_text('\f')
return

# Some dummy functions to save memory/CPU when all that is wanted
# is text. This stops all the image and drawing output from being
Expand Down
3 changes: 0 additions & 3 deletions pdfminer/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ def __init__(
self.fp.write(struct.pack('BBBx', i, i, i))
self.pos0 = self.fp.tell()
self.pos1 = self.pos0 + self.datasize
return

def write_line(self, y: int, data: bytes) -> None:
self.fp.seek(self.pos1 - (y+1)*self.linesize)
self.fp.write(data)
return


class ImageWriter:
Expand All @@ -76,7 +74,6 @@ def __init__(self, outdir: str) -> None:
self.outdir = outdir
if not os.path.exists(self.outdir):
os.makedirs(self.outdir)
return

def export_image(self, image: LTImage) -> str:
(width, height) = image.srcsize
Expand Down
Loading