Skip to content

Commit 2ef3f96

Browse files
authored
STY: Remove excluding Ruff rule RUF005 (#3186)
RUF005: Consider iterable unpacking instead of concatenation.
1 parent 0750365 commit 2ef3f96

File tree

6 files changed

+15
-13
lines changed

6 files changed

+15
-13
lines changed

pypdf/_page.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,9 @@ def _get_ids_image(
622622
if not isinstance(x_object[o], StreamObject):
623623
continue
624624
if x_object[o][IA.SUBTYPE] == "/Image":
625-
lst.append(o if len(ancest) == 0 else ancest + [o])
625+
lst.append(o if len(ancest) == 0 else [*ancest, o])
626626
else: # is a form with possible images inside
627-
lst.extend(self._get_ids_image(x_object[o], ancest + [o], call_stack))
627+
lst.extend(self._get_ids_image(x_object[o], [*ancest, o], call_stack))
628628
assert self.inline_images is not None
629629
lst.extend(list(self.inline_images.keys()))
630630
return lst

pypdf/_writer.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -2074,11 +2074,13 @@ def remove_objects_from_page(
20742074
jump_operators = []
20752075
if to_delete & ObjectDeletionFlag.DRAWING_IMAGES:
20762076
jump_operators = (
2077-
[b"w", b"J", b"j", b"M", b"d", b"i"]
2078-
+ [b"W", b"W*"]
2079-
+ [b"b", b"b*", b"B", b"B*", b"S", b"s", b"f", b"f*", b"F", b"n"]
2080-
+ [b"m", b"l", b"c", b"v", b"y", b"h", b"re"]
2081-
+ [b"sh"]
2077+
[
2078+
b"w", b"J", b"j", b"M", b"d", b"i",
2079+
b"W", b"W*",
2080+
b"b", b"b*", b"B", b"B*", b"S", b"s", b"f", b"f*", b"F", b"n",
2081+
b"m", b"l", b"c", b"v", b"y", b"h", b"re",
2082+
b"sh"
2083+
]
20822084
)
20832085
if to_delete & ObjectDeletionFlag.TEXT:
20842086
jump_operators = [b"Tj", b"TJ", b"'", b'"']
@@ -2698,11 +2700,11 @@ def merge(
26982700
# numbers in the exclude list identifies that the exclusion is
26992701
# only applicable to 1st level of cloning
27002702
srcpages[pg.indirect_reference.idnum] = self.add_page(
2701-
pg, list(excluded_fields) + [1, "/B", 1, "/Annots"] # type: ignore
2703+
pg, [*list(excluded_fields), 1, "/B", 1, "/Annots"] # type: ignore
27022704
)
27032705
else:
27042706
srcpages[pg.indirect_reference.idnum] = self.insert_page(
2705-
pg, position, list(excluded_fields) + [1, "/B", 1, "/Annots"] # type: ignore
2707+
pg, position, [*list(excluded_fields), 1, "/B", 1, "/Annots"] # type: ignore
27062708
)
27072709
position += 1
27082710
srcpages[pg.indirect_reference.idnum].original_page = pg

pypdf/generic/_base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ def write_to_stream(
624624
stream.write(b">")
625625

626626
def __str__(self) -> str:
627-
charset_to_try = ["utf-16"] + list(NameObject.CHARSETS)
627+
charset_to_try = ["utf-16", *list(NameObject.CHARSETS)]
628628
for enc in charset_to_try:
629629
try:
630630
return self.decode(enc)

pypdf/pagerange.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def parse_filename_page_ranges(
173173
pairs: List[Tuple[str, PageRange]] = []
174174
pdf_filename: Union[str, None] = None
175175
did_page_range = False
176-
for arg in args + [None]:
176+
for arg in [*args, None]:
177177
if PageRange.valid(arg):
178178
if not pdf_filename:
179179
raise ValueError(

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ ignore = [
188188
"RET508", # Unnecessary `else` after `break` statement
189189
"RUF001", # Detect confusable Unicode-to-Unicode units. Introduces bugs
190190
"RUF002", # Detect confusable Unicode-to-Unicode units. Introduces bugs
191-
"RUF005", # Detect confusable Unicode-to-Unicode units. Introduces bugs
192191
"S101", # Use of `assert` detected
193192
"S110", # `try`-`except`-`pass` detected, consider logging the exception
194193
"SIM105", # contextlib.suppress

tests/test_page_labels.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ def test_index2label_kids():
135135
"XV",
136136
"XVI",
137137
"XVII",
138-
] + list(map(str, range(1, 284)))
138+
*list(map(str, range(1, 284)))
139+
]
139140
for x in ["20", "44", "58", "82", "94", "116", "154", "166", "192", "224", "250"]:
140141
# Some page labels are unused. Removing them is still easier than copying the
141142
# whole list itself here.

0 commit comments

Comments
 (0)