Skip to content

Commit 59ae169

Browse files
DEV: Update pinned requirements (py-pdf#2918)
* DEV: Update pinned requirements * use new ruff command * apply safe ruff fixes * fix remaining ruff violations * fix mypy issues * further mypy fixes * revert some mypy changes due to too old types-pillow package * update mpypy to version 1.13.0
1 parent 1a6abfd commit 59ae169

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+576
-406
lines changed

.github/workflows/github-ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ jobs:
163163
- name: Test with ruff
164164
run: |
165165
echo `ruff --version`
166-
ruff .
166+
ruff check .
167167
- name: Test with mypy
168168
run : |
169169
mypy pypdf

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
sys.path.insert(0, os.path.abspath("."))
1919
sys.path.insert(0, os.path.abspath("../"))
2020

21-
import pypdf as py_pkg # noqa: E402
21+
import pypdf as py_pkg
2222

2323
shutil.copyfile("../CHANGELOG.md", "meta/CHANGELOG.md")
2424
shutil.copyfile("../CONTRIBUTORS.md", "meta/CONTRIBUTORS.md")

make_release.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def main(changelog_path: str) -> None:
3030
3131
Args:
3232
changelog_path: The location of the CHANGELOG file
33+
3334
"""
3435
changelog = get_changelog(changelog_path)
3536
git_tag = get_most_recent_git_tag()
@@ -66,7 +67,7 @@ def print_instructions(new_version: str) -> None:
6667
print("=" * 80)
6768
print(f"☑ {VERSION_FILE_PATH} was adjusted to '{new_version}'")
6869
print(f"☑ {CHANGELOG_FILE_PATH} was adjusted")
69-
print("")
70+
print()
7071
print("Now run:")
7172
print(" git commit -eF RELEASE_COMMIT_MSG.md")
7273
print(" git push")
@@ -149,6 +150,7 @@ def version_bump(git_tag: str) -> str:
149150
150151
Returns:
151152
The new version where the patch version is bumped.
153+
152154
"""
153155
# just assume a patch version change
154156
major, minor, patch = git_tag.split(".")
@@ -164,6 +166,7 @@ def get_changelog(changelog_path: str) -> str:
164166
165167
Returns:
166168
Data of the CHANGELOG
169+
167170
"""
168171
with open(changelog_path, encoding="utf-8") as fh:
169172
changelog = fh.read()
@@ -177,6 +180,7 @@ def write_changelog(new_changelog: str, changelog_path: str) -> None:
177180
Args:
178181
new_changelog: Contents of the new CHANGELOG
179182
changelog_path: Path where the CHANGELOG file is
183+
180184
"""
181185
with open(changelog_path, "w", encoding="utf-8") as fh:
182186
fh.write(new_changelog)
@@ -191,6 +195,7 @@ def get_formatted_changes(git_tag: str) -> Tuple[str, str]:
191195
192196
Returns:
193197
Changes done since git_tag
198+
194199
"""
195200
commits = get_git_commits_since_tag(git_tag)
196201

@@ -266,6 +271,7 @@ def get_most_recent_git_tag() -> str:
266271
267272
Returns:
268273
Most recently created git tag.
274+
269275
"""
270276
git_tag = str(
271277
subprocess.check_output(
@@ -285,12 +291,13 @@ def get_author_mapping(line_count: int) -> Dict[str, str]:
285291
286292
Returns:
287293
A mapping of long commit hashes to author login handles.
294+
288295
"""
289296
per_page = min(line_count, 100)
290297
page = 1
291298
mapping: Dict[str, str] = {}
292299
for _ in range(0, line_count, per_page):
293-
with urllib.request.urlopen( # noqa: S310
300+
with urllib.request.urlopen(
294301
f"https://api.github.com/repos/{GH_ORG}/{GH_PROJECT}/commits?per_page={per_page}&page={page}"
295302
) as response:
296303
commits = json.loads(response.read())
@@ -310,6 +317,7 @@ def get_git_commits_since_tag(git_tag: str) -> List[Change]:
310317
311318
Returns:
312319
List of all changes since git_tag.
320+
313321
"""
314322
commits = (
315323
subprocess.check_output(
@@ -342,6 +350,7 @@ def parse_commit_line(line: str, authors: Dict[str, str]) -> Change:
342350
343351
Raises:
344352
ValueError: The commit line is not well-structured
353+
345354
"""
346355
parts = line.strip().strip('"\\').split(":::")
347356
if len(parts) != 3:

mutmut_config.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def pre_mutation(context: Context) -> None:
1313
1414
Args:
1515
context: A mutmut Context object
16+
1617
"""
1718
line = context.current_source_line.strip()
1819
if (

pypdf/_cmap.py

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def build_char_map(
2727
Returns:
2828
Font sub-type, space_width criteria (50% of width), encoding, map character-map, font-dictionary.
2929
The font-dictionary itself is suitable for the curious.
30+
3031
"""
3132
ft: DictionaryObject = obj["/Resources"]["/Font"][font_name] # type: ignore
3233
font_subtype, font_halfspace, font_encoding, font_map = build_char_map_from_dict(
@@ -49,6 +50,7 @@ def build_char_map_from_dict(
4950
Returns:
5051
Font sub-type, space_width criteria(50% of width), encoding, map character-map.
5152
The font-dictionary itself is suitable for the curious.
53+
5254
"""
5355
font_type = cast(str, ft["/Subtype"].get_object())
5456
encoding, map_dict = get_encoding(ft)

pypdf/_codecs/_codecs.py

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def encode(self, data: bytes) -> bytes:
2323
2424
Returns:
2525
Encoded data.
26+
2627
"""
2728

2829
@abstractmethod
@@ -35,6 +36,7 @@ def decode(self, data: bytes) -> bytes:
3536
3637
Returns:
3738
Decoded data.
39+
3840
"""
3941

4042

pypdf/_doc_common.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ def get_num_pages(self) -> int:
342342
Raises:
343343
PdfReadError: if file is encrypted and restrictions prevent
344344
this action.
345+
345346
"""
346347
# Flattened pages will not work on an encrypted PDF;
347348
# the PDF file's page count is used in this case. Otherwise,
@@ -365,6 +366,7 @@ def get_page(self, page_number: int) -> PageObject:
365366
366367
Returns:
367368
A :class:`PageObject<pypdf._page.PageObject>` instance.
369+
368370
"""
369371
if self.flattened_pages is None:
370372
self._flatten(self._readonly)
@@ -468,6 +470,7 @@ def _get_named_destinations(
468470
Returns:
469471
A dictionary which maps names to
470472
:class:`Destinations<pypdf.generic.Destination>`.
473+
471474
"""
472475
if retval is None:
473476
retval = {}
@@ -550,6 +553,7 @@ def get_fields(
550553
value is a :class:`Field<pypdf.generic.Field>` object. By
551554
default, the mapping name is used for keys.
552555
``None`` if form data could not be located.
556+
553557
"""
554558
field_attributes = FA.attributes_dict()
555559
field_attributes.update(CheckboxRadioButtonAttributes.attributes_dict())
@@ -700,6 +704,7 @@ def get_form_text_fields(self, full_qualified_name: bool = False) -> Dict[str, A
700704
701705
If the document contains multiple form fields with the same name, the
702706
second and following will get the suffix .2, .3, ...
707+
703708
"""
704709

705710
def indexed_key(k: str, fields: Dict[Any, Any]) -> str:
@@ -745,6 +750,7 @@ def get_pages_showing_field(
745750
- Multi-page list:
746751
Field with multiple kids widgets
747752
(example: radio buttons, field repeated on multiple pages).
753+
748754
"""
749755

750756
def _get_inherited(obj: DictionaryObject, key: str) -> Any:
@@ -806,6 +812,7 @@ def open_destination(
806812
807813
Raises:
808814
Exception: If a destination is invalid.
815+
809816
"""
810817
if "/OpenAction" not in self.root_object:
811818
return None
@@ -917,6 +924,7 @@ def get_page_number(self, page: PageObject) -> Optional[int]:
917924
918925
Returns:
919926
The page number or None if page is not found
927+
920928
"""
921929
return self._get_page_number_by_indirect(page.indirect_reference)
922930

@@ -929,6 +937,7 @@ def get_destination_page_number(self, destination: Destination) -> Optional[int]
929937
930938
Returns:
931939
The page number or None if page is not found
940+
932941
"""
933942
return self._get_page_number_by_indirect(destination.page)
934943

@@ -962,7 +971,7 @@ def _build_destination(
962971
# create a link to first Page
963972
tmp = self.pages[0].indirect_reference
964973
indirect_reference = NullObject() if tmp is None else tmp
965-
return Destination(title, indirect_reference, Fit.fit()) # type: ignore
974+
return Destination(title, indirect_reference, Fit.fit())
966975

967976
def _build_outline_item(self, node: DictionaryObject) -> Optional[Destination]:
968977
dest, title, outline_item = None, None, None
@@ -1135,6 +1144,7 @@ def _flatten(
11351144
pages:
11361145
inherit:
11371146
indirect_reference: Used recursively to flatten the /Pages object.
1147+
11381148
"""
11391149
inheritable_page_attributes = (
11401150
NameObject(PG.RESOURCES),
@@ -1208,6 +1218,7 @@ def remove_page(
12081218
12091219
clean: replace PageObject with NullObject to prevent annotations
12101220
or destinations to reference a detached page.
1221+
12111222
"""
12121223
if self.flattened_pages is None:
12131224
self._flatten(self._readonly)
@@ -1246,6 +1257,7 @@ def _get_indirect_object(self, num: int, gen: int) -> Optional[PdfObject]:
12461257
12471258
Returns:
12481259
A PdfObject
1260+
12491261
"""
12501262
return IndirectObject(num, gen, self).get_object()
12511263

@@ -1333,6 +1345,7 @@ def _list_attachments(self) -> List[str]:
13331345
13341346
Returns:
13351347
list of filenames
1348+
13361349
"""
13371350
catalog = self.root_object
13381351
# From the catalog get the embedded file names
@@ -1371,6 +1384,7 @@ def _get_attachments(
13711384
Returns:
13721385
dictionary of filename -> Union[bytestring or List[ByteString]]
13731386
If the filename exists multiple times a list of the different versions will be provided.
1387+
13741388
"""
13751389
catalog = self.root_object
13761390
# From the catalog get the embedded file names

pypdf/_encryption.py

+13
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ def compute_key(
188188
189189
Returns:
190190
The u_hash digest of length key_size
191+
191192
"""
192193
a = _padding(password)
193194
u_hash = hashlib.md5(a)
@@ -243,6 +244,7 @@ def compute_O_value_key(owner_password: bytes, rev: int, key_size: int) -> bytes
243244
244245
Returns:
245246
The RC4 key
247+
246248
"""
247249
a = _padding(owner_password)
248250
o_hash_digest = hashlib.md5(a).digest()
@@ -266,6 +268,7 @@ def compute_O_value(rc4_key: bytes, user_password: bytes, rev: int) -> bytes:
266268
267269
Returns:
268270
The RC4 encrypted
271+
269272
"""
270273
a = _padding(user_password)
271274
rc4_enc = rc4_encrypt(rc4_key, a)
@@ -297,6 +300,7 @@ def compute_U_value(key: bytes, rev: int, id1_entry: bytes) -> bytes:
297300
298301
Returns:
299302
The value
303+
300304
"""
301305
if rev <= 2:
302306
value = rc4_encrypt(key, _PADDING)
@@ -381,6 +385,7 @@ def verify_user_password(
381385
382386
Returns:
383387
The key
388+
384389
"""
385390
key = AlgV4.compute_key(
386391
user_password, rev, key_size, o_entry, P, id1_entry, metadata_encrypted
@@ -443,6 +448,7 @@ def verify_owner_password(
443448
444449
Returns:
445450
bytes
451+
446452
"""
447453
rc4_key = AlgV4.compute_O_value_key(owner_password, rev, key_size)
448454

@@ -526,6 +532,7 @@ def verify_owner_password(
526532
527533
Returns:
528534
The key
535+
529536
"""
530537
password = password[:127]
531538
if (
@@ -556,6 +563,7 @@ def verify_user_password(
556563
557564
Returns:
558565
bytes
566+
559567
"""
560568
password = password[:127]
561569
if AlgV5.calculate_hash(R, password, u_value[32:40], b"") != u_value[:32]:
@@ -605,6 +613,7 @@ def verify_perms(
605613
606614
Returns:
607615
A boolean
616+
608617
"""
609618
b8 = b"T" if metadata_encrypted else b"F"
610619
p1 = struct.pack("<I", p) + b"\xff\xff\xff\xff" + b8 + b"adb"
@@ -658,6 +667,7 @@ def compute_U_value(R: int, password: bytes, key: bytes) -> Tuple[bytes, bytes]:
658667
659668
Returns:
660669
A tuple (u-value, ue value)
670+
661671
"""
662672
random_bytes = secrets.token_bytes(16)
663673
val_salt = random_bytes[:8]
@@ -702,6 +712,7 @@ def compute_O_value(
702712
703713
Returns:
704714
A tuple (O value, OE value)
715+
705716
"""
706717
random_bytes = secrets.token_bytes(16)
707718
val_salt = random_bytes[:8]
@@ -745,6 +756,7 @@ def compute_Perms_value(key: bytes, p: int, metadata_encrypted: bool) -> bytes:
745756
746757
Returns:
747758
The perms value
759+
748760
"""
749761
b8 = b"T" if metadata_encrypted else b"F"
750762
rr = secrets.token_bytes(4)
@@ -798,6 +810,7 @@ class Encryption:
798810
encrypting embedded file streams that do not have their own
799811
crypt filter specifier.
800812
values: Additional encryption parameters.
813+
801814
"""
802815

803816
def __init__(

0 commit comments

Comments
 (0)