Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STY: Remove excluding Ruff rule RUF005 #3186

Merged
merged 6 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pypdf/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,9 @@ def _get_ids_image(
if not isinstance(x_object[o], StreamObject):
continue
if x_object[o][IA.SUBTYPE] == "/Image":
lst.append(o if len(ancest) == 0 else ancest + [o])
lst.append(o if len(ancest) == 0 else [*ancest, o])
else: # is a form with possible images inside
lst.extend(self._get_ids_image(x_object[o], ancest + [o], call_stack))
lst.extend(self._get_ids_image(x_object[o], [*ancest, o], call_stack))
assert self.inline_images is not None
lst.extend(list(self.inline_images.keys()))
return lst
Expand Down
16 changes: 9 additions & 7 deletions pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2074,11 +2074,13 @@ def remove_objects_from_page(
jump_operators = []
if to_delete & ObjectDeletionFlag.DRAWING_IMAGES:
jump_operators = (
[b"w", b"J", b"j", b"M", b"d", b"i"]
+ [b"W", b"W*"]
+ [b"b", b"b*", b"B", b"B*", b"S", b"s", b"f", b"f*", b"F", b"n"]
+ [b"m", b"l", b"c", b"v", b"y", b"h", b"re"]
+ [b"sh"]
[
b"w", b"J", b"j", b"M", b"d", b"i",
b"W", b"W*",
b"b", b"b*", b"B", b"B*", b"S", b"s", b"f", b"f*", b"F", b"n",
b"m", b"l", b"c", b"v", b"y", b"h", b"re",
b"sh"
]
)
if to_delete & ObjectDeletionFlag.TEXT:
jump_operators = [b"Tj", b"TJ", b"'", b'"']
Expand Down Expand Up @@ -2698,11 +2700,11 @@ def merge(
# numbers in the exclude list identifies that the exclusion is
# only applicable to 1st level of cloning
srcpages[pg.indirect_reference.idnum] = self.add_page(
pg, list(excluded_fields) + [1, "/B", 1, "/Annots"] # type: ignore
pg, [*list(excluded_fields), 1, "/B", 1, "/Annots"] # type: ignore
)
else:
srcpages[pg.indirect_reference.idnum] = self.insert_page(
pg, position, list(excluded_fields) + [1, "/B", 1, "/Annots"] # type: ignore
pg, position, [*list(excluded_fields), 1, "/B", 1, "/Annots"] # type: ignore
)
position += 1
srcpages[pg.indirect_reference.idnum].original_page = pg
Expand Down
2 changes: 1 addition & 1 deletion pypdf/generic/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def write_to_stream(
stream.write(b">")

def __str__(self) -> str:
charset_to_try = ["utf-16"] + list(NameObject.CHARSETS)
charset_to_try = ["utf-16", *list(NameObject.CHARSETS)]
for enc in charset_to_try:
try:
return self.decode(enc)
Expand Down
2 changes: 1 addition & 1 deletion pypdf/pagerange.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def parse_filename_page_ranges(
pairs: List[Tuple[str, PageRange]] = []
pdf_filename: Union[str, None] = None
did_page_range = False
for arg in args + [None]:
for arg in [*args, None]:
if PageRange.valid(arg):
if not pdf_filename:
raise ValueError(
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ ignore = [
"RET508", # Unnecessary `else` after `break` statement
"RUF001", # Detect confusable Unicode-to-Unicode units. Introduces bugs
"RUF002", # Detect confusable Unicode-to-Unicode units. Introduces bugs
"RUF005", # Detect confusable Unicode-to-Unicode units. Introduces bugs
"S101", # Use of `assert` detected
"S110", # `try`-`except`-`pass` detected, consider logging the exception
"SIM105", # contextlib.suppress
Expand Down
3 changes: 2 additions & 1 deletion tests/test_page_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ def test_index2label_kids():
"XV",
"XVI",
"XVII",
] + list(map(str, range(1, 284)))
*list(map(str, range(1, 284)))
]
for x in ["20", "44", "58", "82", "94", "116", "154", "166", "192", "224", "250"]:
# Some page labels are unused. Removing them is still easier than copying the
# whole list itself here.
Expand Down
Loading