Skip to content

Commit 482a484

Browse files
authored
STY: Modify error messages in PdfWriter (#2902)
Also some documentation tweaks in PdfWriter.
1 parent f5c3cf2 commit 482a484

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

pypdf/_writer.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ def set_need_appearances_writer(self, state: bool = True) -> None:
528528
Returns:
529529
None
530530
"""
531-
# See 12.7.2 and 7.7.2 for more information:
531+
# See §12.7.2 and §7.7.2 for more information:
532532
# https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf
533533
try:
534534
# get the AcroForm tree
@@ -716,7 +716,7 @@ def add_js(self, javascript: str) -> None:
716716
Add JavaScript which will launch upon opening this PDF.
717717
718718
Args:
719-
javascript: Your Javascript.
719+
javascript: Your JavaScript.
720720
721721
>>> output.add_js("this.print({bUI:true,bSilent:false,bShrinkToFit:true});")
722722
# Example: This will launch the print window when the PDF is opened.
@@ -741,7 +741,7 @@ def add_js(self, javascript: str) -> None:
741741
NameObject("/JS"): TextStringObject(f"{javascript}"),
742742
}
743743
)
744-
# We need a name for parameterized javascript in the pdf file,
744+
# We need a name for parameterized JavaScript in the PDF file,
745745
# but it can be anything.
746746
js_list.append(create_string_object(str(uuid.uuid4())))
747747
js_list.append(self._add_object(js))
@@ -1605,7 +1605,7 @@ def compress_identical_objects(
16051605
remove_orphans: bool = True,
16061606
) -> None:
16071607
"""
1608-
Parse the PDF file and merge objects that have same hash.
1608+
Parse the PDF file and merge objects that have the same hash.
16091609
This will make objects common to multiple pages.
16101610
Recommended to be used just before writing output.
16111611
@@ -3132,7 +3132,7 @@ def set_page_label(
31323132
31333133
Page indexes must be given starting from 0.
31343134
Labels must have a style, a prefix or both.
3135-
If a range is not assigned any page label a decimal label starting from 1 is applied.
3135+
If a range is not assigned any page label, a decimal label starting from 1 is applied.
31363136
31373137
Args:
31383138
page_index_from: page index of the beginning of the range starting from 0
@@ -3155,17 +3155,17 @@ def set_page_label(
31553155
Default value: 1.
31563156
"""
31573157
if style is None and prefix is None:
3158-
raise ValueError("at least one between style and prefix must be given")
3158+
raise ValueError("At least one of style and prefix must be given")
31593159
if page_index_from < 0:
3160-
raise ValueError("page_index_from must be equal or greater then 0")
3160+
raise ValueError("page_index_from must be greater or equal than 0")
31613161
if page_index_to < page_index_from:
31623162
raise ValueError(
3163-
"page_index_to must be equal or greater then page_index_from"
3163+
"page_index_to must be greater or equal than page_index_from"
31643164
)
31653165
if page_index_to >= len(self.pages):
31663166
raise ValueError("page_index_to exceeds number of pages")
31673167
if start is not None and start != 0 and start < 1:
3168-
raise ValueError("if given, start must be equal or greater than one")
3168+
raise ValueError("If given, start must be greater or equal than one")
31693169

31703170
self._set_page_label(page_index_from, page_index_to, style, prefix, start)
31713171

@@ -3241,8 +3241,8 @@ def _pdf_objectify(obj: Union[Dict[str, Any], str, int, List[Any]]) -> PdfObject
32413241
to_add = DictionaryObject()
32423242
for key, value in obj.items():
32433243
name_key = NameObject(key)
3244-
casted_value = _pdf_objectify(value)
3245-
to_add[name_key] = casted_value
3244+
cast_value = _pdf_objectify(value)
3245+
to_add[name_key] = cast_value
32463246
return to_add
32473247
elif isinstance(obj, str):
32483248
if obj.startswith("/"):

tests/test_writer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,21 +1187,21 @@ def test_set_page_label(pdf_file_path):
11871187
writer = PdfWriter()
11881188
writer.clone_document_from_reader(reader)
11891189
with pytest.raises(
1190-
ValueError, match="at least one between style and prefix must be given"
1190+
ValueError, match="At least one of style and prefix must be given"
11911191
):
11921192
writer.set_page_label(0, 5, start=2)
11931193
with pytest.raises(
1194-
ValueError, match="page_index_from must be equal or greater then 0"
1194+
ValueError, match="page_index_from must be greater or equal than 0"
11951195
):
11961196
writer.set_page_label(-1, 5, "/r")
11971197
with pytest.raises(
1198-
ValueError, match="page_index_to must be equal or greater then page_index_from"
1198+
ValueError, match="page_index_to must be greater or equal than page_index_from"
11991199
):
12001200
writer.set_page_label(5, 0, "/r")
12011201
with pytest.raises(ValueError, match="page_index_to exceeds number of pages"):
12021202
writer.set_page_label(0, 19, "/r")
12031203
with pytest.raises(
1204-
ValueError, match="if given, start must be equal or greater than one"
1204+
ValueError, match="If given, start must be greater or equal than one"
12051205
):
12061206
writer.set_page_label(0, 5, "/r", start=-1)
12071207

0 commit comments

Comments
 (0)