Skip to content

Commit 24a6db1

Browse files
DEV: Sync pre-commit configuration with requirements (#3192)
1 parent d966080 commit 24a6db1

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

.github/workflows/github-ci.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ jobs:
184184
run: |
185185
pip install -r requirements/docs.txt
186186
sphinx-build --nitpicky --fail-on-warning --keep-going --show-traceback --builder html docs build/sphinx/html
187+
- name: Check with pre-commit
188+
run: |
189+
pip install -r requirements/dev.txt
190+
pre-commit run --all-files --show-diff-on-failure
187191
188192
package:
189193
name: Build & verify package

.pre-commit-config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ repos:
44
rev: v5.0.0
55
hooks:
66
- id: check-ast
7-
- id: check-byte-order-marker
87
- id: check-case-conflict
98
- id: check-docstring-first
109
- id: check-yaml
1110
- id: debug-statements
1211
- id: end-of-file-fixer
1312
exclude: "resources/.*|docs/make.bat"
13+
- id: fix-byte-order-marker
1414
- id: trailing-whitespace
1515
- id: mixed-line-ending
1616
args: ['--fix=lf']
@@ -19,7 +19,7 @@ repos:
1919
args: ['--maxkb=1000']
2020

2121
- repo: https://github.com/charliermarsh/ruff-pre-commit
22-
rev: v0.7.0
22+
rev: v0.10.0
2323
hooks:
2424
- id: ruff
2525
args: ['--fix']
@@ -31,7 +31,7 @@ repos:
3131
args: [--py38-plus]
3232

3333
- repo: https://github.com/pre-commit/mirrors-mypy
34-
rev: 'v1.13.0'
34+
rev: 'v1.15.0'
3535
hooks:
3636
- id: mypy
3737
additional_dependencies: [types-Pillow==10.2.0.20240822]

docs/user/extract-attachments.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ reader = PdfReader("example.pdf")
2727

2828
for attachment in reader.attachment_list:
2929
print(attachment.name, attachment.alternative_name, attachment.content)
30-
```
30+
```

pypdf/generic/_files.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Generator, Optional, cast
3+
from typing import TYPE_CHECKING, Generator, cast
44

55
from pypdf._utils import parse_iso8824_date
66
from pypdf.constants import FileSpecificationDictionaryEntries
@@ -29,7 +29,7 @@ def __init__(self, name: str, pdf_object: DictionaryObject) -> None:
2929
self.pdf_object = pdf_object
3030

3131
@property
32-
def alternative_name(self) -> Optional[str]:
32+
def alternative_name(self) -> str | None:
3333
"""Retrieve the alternative name (file specification)."""
3434
for key in [FileSpecificationDictionaryEntries.UF, FileSpecificationDictionaryEntries.F]:
3535
# PDF 2.0 reference, table 43:
@@ -39,7 +39,7 @@ def alternative_name(self) -> Optional[str]:
3939
return None
4040

4141
@property
42-
def description(self) -> Optional[str]:
42+
def description(self) -> str | None:
4343
"""Retrieve the description."""
4444
return self.pdf_object.get(FileSpecificationDictionaryEntries.DESC)
4545

@@ -65,7 +65,7 @@ def _params(self) -> DictionaryObject:
6565
return self._embedded_file.get("/Params", DictionaryObject()).get_object()
6666

6767
@property
68-
def subtype(self) -> Optional[str]:
68+
def subtype(self) -> str | None:
6969
"""Retrieve the subtype. This is a MIME media type, prefixed by a slash."""
7070
return self._embedded_file.get("/Subtype")
7171

@@ -75,30 +75,30 @@ def content(self) -> bytes:
7575
return self._embedded_file.get_data()
7676

7777
@property
78-
def size(self) -> Optional[int]:
78+
def size(self) -> int | None:
7979
"""Retrieve the size of the uncompressed file in bytes."""
8080
return self._params.get("/Size")
8181

8282
@property
83-
def creation_date(self) -> Optional[datetime.datetime]:
83+
def creation_date(self) -> datetime.datetime | None:
8484
"""Retrieve the file creation datetime."""
8585
return parse_iso8824_date(self._params.get("/CreationDate"))
8686

8787
@property
88-
def modification_date(self) -> Optional[datetime.datetime]:
88+
def modification_date(self) -> datetime.datetime | None:
8989
"""Retrieve the datetime of the last file modification."""
9090
return parse_iso8824_date(self._params.get("/ModDate"))
9191

9292
@property
93-
def checksum(self) -> Optional[bytes]:
93+
def checksum(self) -> bytes | None:
9494
"""Retrieve the MD5 checksum of the (uncompressed) file."""
9595
return self._params.get("/CheckSum")
9696

9797
def __repr__(self) -> str:
9898
return f"<{self.__class__.__name__} name={self.name!r}>"
9999

100100
@classmethod
101-
def _load_from_names(cls, names: ArrayObject) -> Generator[EmbeddedFile, None, None]:
101+
def _load_from_names(cls, names: ArrayObject) -> Generator[EmbeddedFile]:
102102
"""
103103
Convert the given name tree into class instances.
104104
@@ -117,7 +117,7 @@ def _load_from_names(cls, names: ArrayObject) -> Generator[EmbeddedFile, None, N
117117
yield EmbeddedFile(name=direct_name, pdf_object=file_dictionary)
118118

119119
@classmethod
120-
def _load(cls, catalog: DictionaryObject) -> Generator[EmbeddedFile, None, None]:
120+
def _load(cls, catalog: DictionaryObject) -> Generator[EmbeddedFile]:
121121
"""
122122
Load the embedded files for the given document catalog.
123123

0 commit comments

Comments
 (0)