Skip to content

STY: Use start argument in enumerate #3251

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

Merged
merged 2 commits into from
Apr 14, 2025
Merged
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
9 changes: 4 additions & 5 deletions pypdf/_writer.py
Original file line number Diff line number Diff line change
@@ -1502,13 +1502,12 @@ def _write_increment(self, stream: StreamType) -> None:

def _write_pdf_structure(self, stream: StreamType) -> Tuple[List[int], List[int]]:
object_positions = []
free_objects = [] # will contain list of all free entries
free_objects = []
stream.write(self.pdf_header.encode() + b"\n")
stream.write(b"%\xE2\xE3\xCF\xD3\n")

for i, obj in enumerate(self._objects):
for idnum, obj in enumerate(self._objects, start=1):
if obj is not None:
idnum = i + 1
object_positions.append(stream.tell())
stream.write(f"{idnum} 0 obj\n".encode())
if self._encryption and obj != self._encrypt_entry:
@@ -1517,8 +1516,8 @@ def _write_pdf_structure(self, stream: StreamType) -> Tuple[List[int], List[int]
stream.write(b"\nendobj\n")
else:
object_positions.append(-1)
free_objects.append(i + 1)
free_objects.append(0) # add 0 to loop in accordance with PDF spec
free_objects.append(idnum)
free_objects.append(0) # add 0 to loop in accordance with specification
return object_positions, free_objects

def _write_xref_table(