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 unnecessary return statements #990

Merged
merged 1 commit into from
Jul 9, 2024
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
Remove unnecessary return statements
  • Loading branch information
pietermarsman committed Jul 9, 2024
commit 29016648a92dc9414e180bf918f5a3051b50d4ab
16 changes: 0 additions & 16 deletions pdfminer/ccitt.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ def __init__(self, width: int, bytealign: bool = False) -> None:
self.width = width
self.bytealign = bytealign
self.reset()
return

def feedbytes(self, data: bytes) -> None:
for byte in get_bytes(data):
Expand All @@ -364,7 +363,6 @@ def feedbytes(self, data: bytes) -> None:
self._state = self.MODE
except self.EOFB:
break
return

def _parse_mode(self, mode: object) -> BitParserState:
if mode == "p":
Expand Down Expand Up @@ -453,18 +451,15 @@ def reset(self) -> None:
self._reset_line()
self._accept = self._parse_mode
self._state = self.MODE
return

def output_line(self, y: int, bits: Sequence[int]) -> None:
print(y, "".join(str(b) for b in bits))
return

def _reset_line(self) -> None:
self._refline = self._curline
self._curline = array.array("b", [1] * self.width)
self._curpos = -1
self._color = 1
return

def _flush_line(self) -> None:
if self.width <= self._curpos:
Expand All @@ -473,7 +468,6 @@ def _flush_line(self) -> None:
self._reset_line()
if self.bytealign:
raise self.ByteSkip
return

def _do_vertical(self, dx: int) -> None:
x1 = self._curpos + 1
Expand All @@ -500,7 +494,6 @@ def _do_vertical(self, dx: int) -> None:
self._curline[x] = self._color
self._curpos = x1
self._color = 1 - self._color
return

def _do_pass(self) -> None:
x1 = self._curpos + 1
Expand Down Expand Up @@ -531,7 +524,6 @@ def _do_pass(self) -> None:
for x in range(self._curpos, x1):
self._curline[x] = self._color
self._curpos = x1
return

def _do_horizontal(self, n1: int, n2: int) -> None:
if self._curpos < 0:
Expand All @@ -548,14 +540,12 @@ def _do_horizontal(self, n1: int, n2: int) -> None:
self._curline[x] = 1 - self._color
x += 1
self._curpos = x
return

def _do_uncompressed(self, bits: str) -> None:
for c in bits:
self._curline[self._curpos] = int(c)
self._curpos += 1
self._flush_line()
return


class CCITTFaxDecoder(CCITTG4Parser):
Expand All @@ -565,7 +555,6 @@ def __init__(
CCITTG4Parser.__init__(self, width, bytealign=bytealign)
self.reversed = reversed
self._buf = b""
return

def close(self) -> bytes:
return self._buf
Expand All @@ -578,7 +567,6 @@ def output_line(self, y: int, bits: Sequence[int]) -> None:
if b:
arr[i // 8] += (128, 64, 32, 16, 8, 4, 2, 1)[i % 8]
self._buf += arr.tobytes()
return


def ccittfaxdecode(data: bytes, params: Dict[str, object]) -> bytes:
Expand Down Expand Up @@ -608,21 +596,18 @@ def __init__(self, width: int, bytealign: bool = False) -> None:

CCITTG4Parser.__init__(self, width, bytealign=bytealign)
self.img = pygame.Surface((self.width, 1000))
return

def output_line(self, y: int, bits: Sequence[int]) -> None:
for (x, b) in enumerate(bits):
if b:
self.img.set_at((x, y), (255, 255, 255))
else:
self.img.set_at((x, y), (0, 0, 0))
return

def close(self) -> None:
import pygame

pygame.image.save(self.img, "out.bmp")
return

for path in argv[1:]:
fp = open(path, "rb")
Expand All @@ -631,4 +616,3 @@ def close(self) -> None:
parser.feedbytes(fp.read())
parser.close()
fp.close()
return
2 changes: 0 additions & 2 deletions pdfminer/cmapdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,12 @@ def __init__(self, cmap: CMapBase, fp: BinaryIO) -> None:
# some ToUnicode maps don't have "begincmap" keyword.
self._in_cmap = True
self._warnings: Set[str] = set()
return

def run(self) -> None:
try:
self.nextobject()
except PSEOF:
pass
return

KEYWORD_BEGINCMAP = KWD(b"begincmap")
KEYWORD_ENDCMAP = KWD(b"endcmap")
Expand Down
34 changes: 3 additions & 31 deletions pdfminer/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,8 @@ def render(item: LTItem) -> None:
# is text. This stops all the image and drawing output from being
# recorded and taking up RAM.
def render_image(self, name: str, stream: PDFStream) -> None:
if self.imagewriter is None:
return
PDFConverter.render_image(self, name, stream)
return
if self.imagewriter is not None:
PDFConverter.render_image(self, name, stream)

def paint_path(
self,
Expand All @@ -370,7 +368,7 @@ def paint_path(
evenodd: bool,
path: Sequence[PathSegment],
) -> None:
return
pass


class HTMLConverter(PDFConverter[AnyIO]):
Expand Down Expand Up @@ -435,14 +433,12 @@ def __init__(
self._font: Optional[Tuple[str, float]] = None
self._fontstack: List[Optional[Tuple[str, float]]] = []
self.write_header()
return

def write(self, text: str) -> None:
if self.codec:
cast(BinaryIO, self.outfp).write(text.encode(self.codec))
else:
cast(TextIO, self.outfp).write(text)
return

def write_header(self) -> None:
self.write("<html><head>\n")
Expand All @@ -455,7 +451,6 @@ def write_header(self) -> None:
s = '<meta http-equiv="Content-Type" content="text/html">\n'
self.write(s)
self.write("</head><body>\n")
return

def write_footer(self) -> None:
page_links = [f'<a href="#{i}">{i}</a>' for i in range(1, self.pageno)]
Expand All @@ -464,11 +459,9 @@ def write_footer(self) -> None:
)
self.write(s)
self.write("</body></html>\n")
return

def write_text(self, text: str) -> None:
self.write(enc(text))
return

def place_rect(
self, color: str, borderwidth: int, x: float, y: float, w: float, h: float
Expand All @@ -488,11 +481,9 @@ def place_rect(
)
)
self.write(s)
return

def place_border(self, color: str, borderwidth: int, item: LTComponent) -> None:
self.place_rect(color, borderwidth, item.x0, item.y1, item.width, item.height)
return

def place_image(
self, item: LTImage, borderwidth: int, x: float, y: float, w: float, h: float
Expand All @@ -512,7 +503,6 @@ def place_image(
)
)
self.write(s)
return

def place_text(
self, color: str, text: str, x: float, y: float, size: float
Expand All @@ -532,7 +522,6 @@ def place_text(
self.write(s)
self.write_text(text)
self.write("</span>\n")
return

def begin_div(
self,
Expand Down Expand Up @@ -561,14 +550,12 @@ def begin_div(
)
)
self.write(s)
return

def end_div(self, color: str) -> None:
if self._font is not None:
self.write("</span>")
self._font = self._fontstack.pop()
self.write("</div>")
return

def put_text(self, text: str, fontname: str, fontsize: float) -> None:
font = (fontname, fontsize)
Expand All @@ -583,19 +570,16 @@ def put_text(self, text: str, fontname: str, fontsize: float) -> None:
)
self._font = font
self.write_text(text)
return

def put_newline(self) -> None:
self.write("<br>")
return

def receive_layout(self, ltpage: LTPage) -> None:
def show_group(item: Union[LTTextGroup, TextGroupElement]) -> None:
if isinstance(item, LTTextGroup):
self.place_border("textgroup", 1, item)
for child in item:
show_group(child)
return

def render(item: LTItem) -> None:
child: LTItem
Expand Down Expand Up @@ -668,15 +652,12 @@ def render(item: LTItem) -> None:
self.put_text(item.get_text(), fontname, item.size)
elif isinstance(item, LTText):
self.write_text(item.get_text())
return

render(ltpage)
self._yoffset += self.pagemargin
return

def close(self) -> None:
self.write_footer()
return


class XMLConverter(PDFConverter[AnyIO]):
Expand Down Expand Up @@ -704,32 +685,27 @@ def __init__(
self.imagewriter = imagewriter
self.stripcontrol = stripcontrol
self.write_header()
return

def write(self, text: str) -> None:
if self.codec:
cast(BinaryIO, self.outfp).write(text.encode(self.codec))
else:
cast(TextIO, self.outfp).write(text)
return

def write_header(self) -> None:
if self.codec:
self.write('<?xml version="1.0" encoding="%s" ?>\n' % self.codec)
else:
self.write('<?xml version="1.0" ?>\n')
self.write("<pages>\n")
return

def write_footer(self) -> None:
self.write("</pages>\n")
return

def write_text(self, text: str) -> None:
if self.stripcontrol:
text = self.CONTROL.sub("", text)
self.write(enc(text))
return

def receive_layout(self, ltpage: LTPage) -> None:
def show_group(item: LTItem) -> None:
Expand All @@ -743,7 +719,6 @@ def show_group(item: LTItem) -> None:
for child in item:
show_group(child)
self.write("</textgroup>\n")
return

def render(item: LTItem) -> None:
child: LTItem
Expand Down Expand Up @@ -837,14 +812,11 @@ def render(item: LTItem) -> None:
)
else:
assert False, str(("Unhandled", item))
return

render(ltpage)
return

def close(self) -> None:
self.write_footer()
return


class HOCRConverter(PDFConverter[AnyIO]):
Expand Down
Loading
Loading