Skip to content

Commit 17632b0

Browse files
authored
Merge branch 'main' into google-style-docstrings
2 parents 57021ef + c95eabf commit 17632b0

7 files changed

Lines changed: 27 additions & 36 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ build
88
dist/*
99
__pycache__/
1010

11+
# in-project virtual environments
12+
venv/
13+
.venv/
14+
1115
#
1216
.mutmut-cache
1317
mutmut-results.*

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ history and [GitHubs 'Contributors' feature](https://github.com/py-pdf/PyPDF2/gr
1414
* [DL6ER](https://github.com/DL6ER)
1515
* [ediamondscience](https://github.com/ediamondscience)
1616
* [Górny, Michał](https://github.com/mgorny)
17+
* [Hale, Joseph](https://github.com/thehale)
1718
* [JianzhengLuo](https://github.com/JianzhengLuo)
1819
* [Karvonen, Harry](https://github.com/Hatell/)
1920
* [KourFrost](https://github.com/KourFrost)

PyPDF2/_protocols.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""Helpers for working with PDF types."""
22

3-
from io import BufferedReader, BufferedWriter, BytesIO, FileIO
43
from pathlib import Path
5-
from typing import Any, Dict, List, Optional, Tuple, Union
4+
from typing import IO, Any, Dict, List, Optional, Tuple, Union
65

76
try:
87
# Python 3.8+: https://peps.python.org/pep-0586
@@ -59,7 +58,5 @@ class PdfWriterProtocol(Protocol): # pragma: no cover
5958
def get_object(self, indirect_reference: Any) -> Optional[PdfObjectProtocol]:
6059
...
6160

62-
def write(
63-
self, stream: Union[Path, StrByteType]
64-
) -> Tuple[bool, Union[FileIO, BytesIO, BufferedReader, BufferedWriter]]:
61+
def write(self, stream: Union[Path, StrByteType]) -> Tuple[bool, IO]:
6562
...

PyPDF2/_utils.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,10 @@
3434
import warnings
3535
from codecs import getencoder
3636
from dataclasses import dataclass
37-
from io import (
38-
DEFAULT_BUFFER_SIZE,
39-
BufferedReader,
40-
BufferedWriter,
41-
BytesIO,
42-
FileIO,
43-
)
37+
from io import DEFAULT_BUFFER_SIZE
4438
from os import SEEK_CUR
4539
from typing import (
40+
IO,
4641
Any,
4742
Callable,
4843
Dict,
@@ -68,7 +63,7 @@
6863
float, float, float, float, float, float
6964
]
7065

71-
StreamType = Union[BytesIO, BufferedReader, BufferedWriter, FileIO]
66+
StreamType = IO
7267
StrByteType = Union[str, StreamType]
7368

7469
DEPR_MSG_NO_REPLACEMENT = "{} is deprecated and will be removed in PyPDF2 {}."

PyPDF2/_writer.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@
3838
import uuid
3939
import warnings
4040
from hashlib import md5
41-
from io import BufferedReader, BufferedWriter, BytesIO, FileIO, IOBase
41+
from io import BytesIO, FileIO, IOBase
4242
from pathlib import Path
4343
from types import TracebackType
4444
from typing import (
45+
IO,
4546
Any,
4647
Callable,
4748
Deque,
@@ -962,9 +963,7 @@ def write_stream(self, stream: StreamType) -> None:
962963
self._write_trailer(stream)
963964
stream.write(b_(f"\nstartxref\n{xref_location}\n%%EOF\n")) # eof
964965

965-
def write(
966-
self, stream: Union[Path, StrByteType]
967-
) -> Tuple[bool, Union[FileIO, BytesIO, BufferedReader, BufferedWriter]]:
966+
def write(self, stream: Union[Path, StrByteType]) -> Tuple[bool, IO]:
968967
"""
969968
Write the collection of pages added to this object out as a PDF file.
970969
@@ -1289,7 +1288,7 @@ def add_outline_item_destination(
12891288
page_destination: Union[None, PageObject, TreeObject] = None,
12901289
parent: Union[None, TreeObject, IndirectObject] = None,
12911290
before: Union[None, TreeObject, IndirectObject] = None,
1292-
dest: Union[None, PageObject, TreeObject] = None, # deprecated
1291+
dest: Union[None, PageObject, TreeObject] = None, # deprecated
12931292
) -> IndirectObject:
12941293
if page_destination is not None and dest is not None: # deprecated
12951294
raise ValueError(
@@ -2483,7 +2482,9 @@ def _add_articles_thread(
24832482
pag_obj = cast("PageObject", pag.get_object())
24842483
if "/B" not in pag_obj:
24852484
pag_obj[NameObject("/B")] = ArrayObject()
2486-
cast("ArrayObject", pag_obj["/B"]).append(new_article.indirect_reference)
2485+
cast("ArrayObject", pag_obj["/B"]).append(
2486+
new_article.indirect_reference
2487+
)
24872488
current_article = cast("DictionaryObject", current_article["/N"])
24882489
if current_article == first_article:
24892490
new_article[NameObject("/N")] = new_first.indirect_reference # type: ignore
@@ -2674,7 +2675,10 @@ def find_outline_item(
26742675

26752676
i = 0
26762677
while o is not None:
2677-
if o.indirect_reference == outline_item or o.get("/Title", None) == outline_item:
2678+
if (
2679+
o.indirect_reference == outline_item
2680+
or o.get("/Title", None) == outline_item
2681+
):
26782682
return [i]
26792683
else:
26802684
if "/First" in o:

requirements/dev.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
black
2+
pillow
23
pip-tools
34
pre-commit<2.18.0
45
pytest-cov

requirements/dev.txt

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
2-
# This file is autogenerated by pip-compile with python 3.7
3-
# To update, run:
2+
# This file is autogenerated by pip-compile with Python 3.8
3+
# by the following command:
44
#
55
# pip-compile requirements/dev.in
66
#
@@ -38,13 +38,6 @@ identify==2.5.9
3838
# via pre-commit
3939
idna==3.4
4040
# via requests
41-
importlib-metadata==5.1.0
42-
# via
43-
# build
44-
# click
45-
# pre-commit
46-
# pytest
47-
# virtualenv
4841
iniconfig==1.1.1
4942
# via pytest
5043
mypy-extensions==0.4.3
@@ -59,6 +52,8 @@ pathspec==0.10.3
5952
# via black
6053
pep517==0.13.0
6154
# via build
55+
pillow==9.3.0
56+
# via -r requirements/dev.in
6257
pip-tools==6.11.0
6358
# via -r requirements/dev.in
6459
platformdirs==2.6.0
@@ -87,12 +82,8 @@ tomli==2.0.1
8782
# pytest
8883
tomli-w==1.0.0
8984
# via flit
90-
typed-ast==1.5.4
91-
# via black
9285
typing-extensions==4.4.0
93-
# via
94-
# black
95-
# importlib-metadata
86+
# via black
9687
urllib3==1.26.13
9788
# via requests
9889
virtualenv==20.17.1
@@ -101,8 +92,6 @@ wheel==0.38.4
10192
# via
10293
# -r requirements/dev.in
10394
# pip-tools
104-
zipp==3.11.0
105-
# via importlib-metadata
10695

10796
# The following packages are considered to be unsafe in a requirements file:
10897
# pip

0 commit comments

Comments
 (0)