Skip to content

Commit 27edc06

Browse files
authored
DOC: Comment changes in PdfReader (py-pdf#2990)
1 parent 3afc3c0 commit 27edc06

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

pypdf/_reader.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def __init__(
116116
) -> None:
117117
self.strict = strict
118118
self.flattened_pages: Optional[List[PageObject]] = None
119+
119120
#: Storage of parsed PDF objects.
120121
self.resolved_objects: Dict[Tuple[Any, Any], Optional[PdfObject]] = {}
121122

@@ -430,7 +431,7 @@ def get_object(
430431
idnum = -1
431432
generation = -1 # exception will be raised below
432433
if idnum != indirect_reference.idnum and self.xref_index:
433-
# Xref table probably had bad indexes due to not being zero-indexed
434+
# xref table probably had bad indexes due to not being zero-indexed
434435
if self.strict:
435436
raise PdfReadError(
436437
f"Expected object ID ({indirect_reference.idnum} {indirect_reference.generation}) "
@@ -441,9 +442,8 @@ def get_object(
441442
elif idnum != indirect_reference.idnum and self.strict:
442443
# some other problem
443444
raise PdfReadError(
444-
f"Expected object ID ({indirect_reference.idnum} "
445-
f"{indirect_reference.generation}) does not match actual "
446-
f"({idnum} {generation})."
445+
f"Expected object ID ({indirect_reference.idnum} {indirect_reference.generation}) "
446+
f"does not match actual ({idnum} {generation})."
447447
)
448448
if self.strict:
449449
assert generation == indirect_reference.generation
@@ -511,7 +511,7 @@ def get_object(
511511
def read_object_header(self, stream: StreamType) -> Tuple[int, int]:
512512
# Should never be necessary to read out whitespace, since the
513513
# cross-reference table should put us in the right spot to read the
514-
# object header. In reality some files have stupid cross reference
514+
# object header. In reality some files have stupid cross-reference
515515
# tables that are off by whitespace bytes.
516516
extra = False
517517
skip_over_comment(stream)
@@ -558,7 +558,7 @@ def cache_indirect_object(
558558
return obj
559559

560560
def _replace_object(self, indirect: IndirectObject, obj: PdfObject) -> PdfObject:
561-
# function reserved for future dev
561+
# function reserved for future development
562562
if indirect.pdf != self:
563563
raise ValueError("Cannot update PdfReader with external object")
564564
if (indirect.generation, indirect.idnum) not in self.resolved_objects:
@@ -580,14 +580,14 @@ def read(self, stream: StreamType) -> None:
580580
startxref = self._find_startxref_pos(stream)
581581
self._startxref = startxref
582582

583-
# check and eventually correct the startxref only in not strict
583+
# check and eventually correct the startxref only if not strict
584584
xref_issue_nr = self._get_xref_issues(stream, startxref)
585585
if xref_issue_nr != 0:
586586
if self.strict and xref_issue_nr:
587587
raise PdfReadError("Broken xref table")
588588
logger_warning(f"incorrect startxref pointer({xref_issue_nr})", __name__)
589589

590-
# read all cross reference tables and their trailers
590+
# read all cross-reference tables and their trailers
591591
self._read_xref_tables_and_trailers(stream, startxref, xref_issue_nr)
592592

593593
# if not zero-indexed, verify that the table is correct; change it if necessary
@@ -598,7 +598,7 @@ def read(self, stream: StreamType) -> None:
598598
continue
599599
xref_k = sorted(
600600
xref_entry.keys()
601-
) # must ensure ascendant to prevent damage
601+
) # ensure ascending to prevent damage
602602
for id in xref_k:
603603
stream.seek(xref_entry[id], 0)
604604
try:
@@ -962,8 +962,8 @@ def _read_pdf15_xref_stream(
962962
assert cast(str, xrefstream["/Type"]) == "/XRef"
963963
self.cache_indirect_object(generation, idnum, xrefstream)
964964
stream_data = BytesIO(xrefstream.get_data())
965-
# Index pairs specify the subsections in the dictionary. If
966-
# none create one subsection that spans everything.
965+
# Index pairs specify the subsections in the dictionary.
966+
# If none, create one subsection that spans everything.
967967
idx_pairs = xrefstream.get("/Index", [0, xrefstream.get("/Size")])
968968
entry_sizes = cast(Dict[Any, Any], xrefstream.get("/W"))
969969
assert len(entry_sizes) >= 3
@@ -1067,7 +1067,7 @@ def _rebuild_xref_table(self, stream: StreamType) -> None:
10671067
f" whereas {o.get('/N')} expected",
10681068
__name__,
10691069
)
1070-
except Exception: # could be of many cause
1070+
except Exception: # could be multiple causes
10711071
pass
10721072

10731073
stream.seek(0, 0)
@@ -1174,7 +1174,7 @@ def add_form_topname(self, name: str) -> Optional[DictionaryObject]:
11741174
return None
11751175
acroform = cast(DictionaryObject, catalog[NameObject("/AcroForm")])
11761176
if "/Fields" not in acroform:
1177-
# TODO: :No error returns but may be extended for XFA Forms
1177+
# TODO: No error but this may be extended for XFA Forms
11781178
return None
11791179

11801180
interim = DictionaryObject()

0 commit comments

Comments
 (0)