Skip to content

Commit faa8c68

Browse files
authored
MAINT: Update requirements + mypy fixes (#2275)
1 parent 06c1a19 commit faa8c68

12 files changed

+60
-42
lines changed

.pre-commit-config.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# pre-commit run --all-files
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v4.4.0
4+
rev: v4.5.0
55
hooks:
66
- id: check-ast
77
- id: check-byte-order-marker
@@ -18,7 +18,7 @@ repos:
1818
- id: check-added-large-files
1919
args: ['--maxkb=1000']
2020
- repo: https://github.com/psf/black
21-
rev: 23.9.1
21+
rev: 23.10.1
2222
hooks:
2323
- id: black
2424
args: [--target-version, py36]
@@ -29,12 +29,12 @@ repos:
2929
additional_dependencies: [black==22.1.0]
3030
exclude: "docs/user/robustness.md"
3131
- repo: https://github.com/charliermarsh/ruff-pre-commit
32-
rev: v0.0.290
32+
rev: v0.1.3
3333
hooks:
3434
- id: ruff
3535
args: ['--fix']
3636
- repo: https://github.com/asottile/pyupgrade
37-
rev: v3.12.0
37+
rev: v3.15.0
3838
hooks:
3939
- id: pyupgrade
4040
args: [--py36-plus]
@@ -45,7 +45,7 @@ repos:
4545
args: ["--ignore", "E,W,F"]
4646

4747
- repo: https://github.com/pre-commit/mirrors-mypy
48-
rev: 'v1.5.1'
48+
rev: 'v1.6.1'
4949
hooks:
5050
- id: mypy
5151
additional_dependencies: [types-Pillow==10.0.0.2]

docs/user/merging-pdfs.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ It means that you may copy lots of objects which will be saved in the output PDF
131131
In order to prevent this, you can provide the list of fields in the dictionaries to be ignored:
132132

133133
```python
134-
new_page = writer.add_page(reader.pages[0], excluded_fields=["/B"])
134+
new_page = writer.add_page(reader.pages[0], excluded_fields=["/B"])
135135
```
136136

137137
### Merging rotated pages

make_release.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ def get_formatted_changes(git_tag: str) -> Tuple[str, str]:
197197
for commit in commits:
198198
if commit.prefix not in grouped:
199199
grouped[commit.prefix] = []
200-
grouped[commit.prefix].append({"msg": commit.message, "author": commit.author_login})
200+
grouped[commit.prefix].append(
201+
{"msg": commit.message, "author": commit.author_login}
202+
)
201203

202204
# Order prefixes
203205
order = [
@@ -240,9 +242,7 @@ def get_formatted_changes(git_tag: str) -> Tuple[str, str]:
240242
output_with_user += tmp
241243
for commit in grouped[prefix]:
242244
output += f"- {commit['msg']}\n"
243-
output_with_user += (
244-
f"- {commit['msg']} by @{commit['author']}\n"
245-
)
245+
output_with_user += f"- {commit['msg']} by @{commit['author']}\n"
246246
del grouped[prefix]
247247

248248
if grouped:
@@ -357,7 +357,11 @@ def parse_commit_line(line: str, authors: Dict[str, str]) -> Change:
357357
prefix = "DOC"
358358

359359
return Change(
360-
commit_hash=commit_hash, prefix=prefix, message=message, author=author, author_login=author_login
360+
commit_hash=commit_hash,
361+
prefix=prefix,
362+
message=message,
363+
author=author,
364+
author_login=author_login,
361365
)
362366

363367

pypdf/_utils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import functools
3333
import logging
3434
import re
35+
import sys
3536
import warnings
3637
from dataclasses import dataclass
3738
from datetime import datetime, timezone
@@ -51,10 +52,10 @@
5152
overload,
5253
)
5354

54-
try:
55+
if sys.version_info[:2] >= (3, 10):
5556
# Python 3.10+: https://www.python.org/dev/peps/pep-0484/
5657
from typing import TypeAlias
57-
except ImportError:
58+
else:
5859
from typing_extensions import TypeAlias
5960

6061
from .errors import (

pypdf/_xobj_image_helpers.py

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Code in here is only used by pypdf.filters._xobj_to_image"""
22

3+
import sys
34
from io import BytesIO
45
from typing import Any, List, Tuple, Union, cast
56

@@ -14,12 +15,17 @@
1415
NullObject,
1516
)
1617

17-
try:
18-
from typing import Literal, TypeAlias
19-
except ImportError:
18+
if sys.version_info[:2] >= (3, 8):
19+
from typing import Literal
20+
else:
2021
# PEP 586 introduced typing.Literal with Python 3.8
2122
# For older Python versions, the backport typing_extensions is necessary:
22-
from typing_extensions import Literal, TypeAlias # type: ignore[assignment]
23+
from typing_extensions import Literal # type: ignore[assignment]
24+
25+
if sys.version_info[:2] >= (3, 10):
26+
from typing import TypeAlias
27+
else:
28+
from typing_extensions import TypeAlias
2329

2430

2531
try:
@@ -70,22 +76,28 @@ def _get_imagemode(
7076
color_space = color_space[1]
7177
if isinstance(color_space, IndirectObject):
7278
color_space = color_space.get_object()
73-
mode2, invert_color = _get_imagemode(color_space, color_components, prev_mode, depth + 1)
79+
mode2, invert_color = _get_imagemode(
80+
color_space, color_components, prev_mode, depth + 1
81+
)
7482
if mode2 in ("RGB", "CMYK"):
7583
mode2 = "P"
7684
return mode2, invert_color
7785
elif color_space[0] == "/Separation":
7886
color_space = color_space[2]
7987
if isinstance(color_space, IndirectObject):
8088
color_space = color_space.get_object()
81-
mode2, invert_color = _get_imagemode(color_space, color_components, prev_mode, depth + 1)
89+
mode2, invert_color = _get_imagemode(
90+
color_space, color_components, prev_mode, depth + 1
91+
)
8292
return mode2, True
8393
elif color_space[0] == "/DeviceN":
8494
color_components = len(color_space[1])
8595
color_space = color_space[2]
8696
if isinstance(color_space, IndirectObject): # pragma: no cover
8797
color_space = color_space.get_object()
88-
mode2, invert_color = _get_imagemode(color_space, color_components, prev_mode, depth + 1)
98+
mode2, invert_color = _get_imagemode(
99+
color_space, color_components, prev_mode, depth + 1
100+
)
89101
return mode2, invert_color
90102

91103
mode_map = {

pypdf/annotations/_markup_annotations.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from abc import ABC
23
from typing import TYPE_CHECKING, Any, List, Optional, Tuple, Union
34

@@ -14,9 +15,9 @@
1415
from ..generic._utils import hex_to_rgb
1516
from ._base import NO_FLAGS, AnnotationDictionary
1617

17-
try:
18+
if sys.version_info[:2] >= (3, 10):
1819
from typing import TypeAlias
19-
except ImportError:
20+
else:
2021
# PEP 613 introduced typing.TypeAlias with Python 3.10
2122
# For older Python versions, the backport typing_extensions is necessary:
2223
from typing_extensions import TypeAlias

pypdf/types.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
"""Helpers for working with PDF types."""
22

3+
import sys
34
from typing import List, Union
45

5-
try:
6+
if sys.version_info[:2] >= (3, 8):
67
# Python 3.8+: https://peps.python.org/pep-0586
78
from typing import Literal
8-
except ImportError:
9+
else:
910
from typing_extensions import Literal # type: ignore[assignment]
1011

11-
try:
12+
if sys.version_info[:2] >= (3, 10):
1213
# Python 3.10+: https://www.python.org/dev/peps/pep-0484/
1314
from typing import TypeAlias
14-
except ImportError:
15+
else:
1516
from typing_extensions import TypeAlias
1617

1718
from .generic._base import NameObject, NullObject, NumberObject

requirements/dev.txt

+6-6
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-
# by the following command:
2+
# This file is autogenerated by pip-compile with python 3.7
3+
# To update, run:
44
#
55
# pip-compile requirements/dev.in
66
#
@@ -12,7 +12,7 @@ certifi==2023.7.22
1212
# via requests
1313
cfgv==3.3.1
1414
# via pre-commit
15-
charset-normalizer==3.3.0
15+
charset-normalizer==3.3.1
1616
# via requests
1717
click==8.1.7
1818
# via
@@ -70,7 +70,7 @@ pre-commit==2.17.0
7070
# via -r requirements/dev.in
7171
pyproject-hooks==1.0.0
7272
# via build
73-
pytest==7.4.2
73+
pytest==7.4.3
7474
# via pytest-cov
7575
pytest-cov==4.1.0
7676
# via -r requirements/dev.in
@@ -96,9 +96,9 @@ typing-extensions==4.7.1
9696
# black
9797
# importlib-metadata
9898
# platformdirs
99-
urllib3==2.0.6
99+
urllib3==2.0.7
100100
# via requests
101-
virtualenv==20.24.5
101+
virtualenv==20.24.6
102102
# via pre-commit
103103
wheel==0.41.2
104104
# via

requirements/docs.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ alabaster==0.7.13
88
# via sphinx
99
attrs==23.1.0
1010
# via -r requirements/docs.in
11-
babel==2.13.0
11+
babel==2.13.1
1212
# via sphinx
1313
certifi==2023.7.22
1414
# via requests
15-
charset-normalizer==3.3.0
15+
charset-normalizer==3.3.1
1616
# via requests
1717
docutils==0.17.1
1818
# via
@@ -81,7 +81,7 @@ typing-extensions==4.7.1
8181
# via
8282
# importlib-metadata
8383
# markdown-it-py
84-
urllib3==2.0.6
84+
urllib3==2.0.7
8585
# via requests
8686
zipp==3.15.0
8787
# via importlib-metadata

tests/test_encryption.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ def test_aes_decrypt_corrupted_data():
343343
for num in [0, 17, 32]:
344344
aes.decrypt(secrets.token_bytes(num))
345345

346+
346347
def test_encrypt_stream_dictionary(pdf_file_path):
347348
user_password = secrets.token_urlsafe(10)
348349

@@ -353,9 +354,9 @@ def test_encrypt_stream_dictionary(pdf_file_path):
353354
writer = PdfWriter()
354355
writer.add_page(reader.pages[0])
355356
writer.encrypt(
356-
user_password=user_password,
357-
owner_password=None,
358-
algorithm="RC4-128",
357+
user_password=user_password,
358+
owner_password=None,
359+
algorithm="RC4-128",
359360
)
360361
with open(pdf_file_path, "wb") as output_stream:
361362
writer.write(output_stream)

tests/test_utils.py

-2
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ def foo(old_param: int = 1, baz: int = 2) -> None:
241241
def test_deprecate_with_replacement():
242242
def foo() -> None:
243243
deprecate_with_replacement("foo", "bar", removed_in="4.3.2")
244-
pass
245244

246245
with pytest.warns(
247246
DeprecationWarning,
@@ -253,7 +252,6 @@ def foo() -> None:
253252
def test_deprecation_no_replacement():
254253
def foo() -> None:
255254
deprecation_no_replacement("foo", removed_in="4.3.2")
256-
pass
257255

258256
with pytest.raises(
259257
DeprecationError,

tests/test_xobject_image_helpers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_get_imagemode_recursion_depth():
2121
target = b"\n10 0 obj\n[ /DeviceN [ /HKS#2044#20K /Magenta /Yellow /Black ] 10 0 R 11 0 R 12 0 R ]\nendobj\n"
2222
reader = PdfReader(BytesIO(content.replace(source, target)))
2323
with pytest.raises(
24-
PdfReadError,
25-
match="Color spaces nested too deep. If required, consider increasing MAX_IMAGE_MODE_NESTING_DEPTH."
24+
PdfReadError,
25+
match="Color spaces nested too deep. If required, consider increasing MAX_IMAGE_MODE_NESTING_DEPTH.",
2626
):
2727
reader.pages[0].images[0]

0 commit comments

Comments
 (0)