Skip to content

Commit

Permalink
Merge branch 'main' into nbits-image
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma authored Jul 15, 2023
2 parents 8ad0141 + e897809 commit d7708e1
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 27 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ repos:
# hooks:
# - id: mypy
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black
args: [--target-version, py36]
- repo: https://github.com/asottile/blacken-docs
rev: 1.14.0
rev: 1.15.0
hooks:
- id: blacken-docs
additional_dependencies: [black==22.1.0]
exclude: "docs/user/robustness.md"
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.275'
rev: 'v0.0.278'
hooks:
- id: ruff
args: ['--fix']
- repo: https://github.com/asottile/pyupgrade
rev: v3.7.0
rev: v3.9.0
hooks:
- id: pyupgrade
args: [--py36-plus]
Expand Down
5 changes: 1 addition & 4 deletions pypdf/_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,7 @@ def encrypt_object(self, obj: PdfObject) -> PdfObject:
obj2[key] = self.encrypt_object(value)
obj = obj2
elif isinstance(obj, ArrayObject):
obj2 = ArrayObject() # type: ignore
for x in obj:
obj2.append(self.encrypt_object(x)) # type: ignore
obj = obj2
obj = ArrayObject(self.encrypt_object(x) for x in obj) # type: ignore
return obj

def decrypt_object(self, obj: PdfObject) -> PdfObject:
Expand Down
4 changes: 2 additions & 2 deletions pypdf/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ def replace_contents(
self[NameObject(PG.CONTENTS)] = content

def merge_page(
self, page2: "PageObject", expand: bool = False, over: bool = True
self, page2: "PageObject", expand: bool = False, over: bool = True
) -> None:
"""
Merge the content streams of two pages into one.
Expand Down Expand Up @@ -1046,7 +1046,7 @@ def _merge_page(
annots = page[PG.ANNOTS]
if isinstance(annots, ArrayObject):
for ref in annots:
new_annots.append(ref)
new_annots.append(ref) # noqa: PERF402

for res in (
RES.EXT_G_STATE,
Expand Down
6 changes: 1 addition & 5 deletions pypdf/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2217,11 +2217,7 @@ def _list_attachments(self) -> List[str]:
)
except KeyError:
return []
attachments_names = []
# Loop through attachments
for f in filenames:
if isinstance(f, str):
attachments_names.append(f)
attachments_names = [f for f in filenames if isinstance(f, str)]
return attachments_names

def _get_attachment_list(self, name: str) -> List[bytes]:
Expand Down
9 changes: 2 additions & 7 deletions pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,9 +956,7 @@ def update_page_form_field_values(
or self._get_qualified_field_name(writer_annot) == field
):
if isinstance(value, list):
lst = ArrayObject()
for v in value:
lst.append(TextStringObject(v))
lst = ArrayObject(TextStringObject(v) for v in value)
writer_annot[NameObject(FA.V)] = lst
else:
writer_annot[NameObject(FA.V)] = TextStringObject(value)
Expand Down Expand Up @@ -3395,10 +3393,7 @@ def _pdf_objectify(obj: Union[Dict[str, Any], str, int, List[Any]]) -> PdfObject
to_add[name_key] = casted_value
return to_add
elif isinstance(obj, list):
arr = ArrayObject()
for el in obj:
arr.append(_pdf_objectify(el))
return arr
return ArrayObject(_pdf_objectify(el) for el in obj)
elif isinstance(obj, str):
if obj.startswith("/"):
return NameObject(obj)
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ ignore = [
"S101", # Use of `assert` detected
"SLF001", # Private member accessed
"PD011", # Use `.to_numpy()` instead of `.values`
"FA102", # Missing `from __future__ import annotations`, but uses PEP 604 union
"PERF203", # `try`-`except` within a loop incurs performance overhead
]

[tool.ruff.per-file-ignores]
Expand Down
2 changes: 1 addition & 1 deletion requirements/ci-3.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pytest-socket==0.6.0
# via -r requirements/ci.in
pytest-timeout==2.1.0
# via -r requirements/ci.in
ruff==0.0.275
ruff==0.0.278
# via -r requirements/ci.in
typeguard==3.0.2
# via -r requirements/ci.in
Expand Down
2 changes: 1 addition & 1 deletion tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def get_dest_pages(x) -> int:

# oi can be destination or a list:preferred to just print them
for oi in outline:
out.append(get_dest_pages(oi))
out.append(get_dest_pages(oi)) # noqa: PERF401


def test_decode_permissions():
Expand Down
4 changes: 1 addition & 3 deletions tests/test_xmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ def get_all_tiff(xmp: pypdf.xmp.XmpInformation):
about_uri="", namespace="http://ns.adobe.com/tiff/1.0/"
)
for tag in tiff_ns:
contents = []
for content in tag.childNodes:
contents.append(content.data)
contents = [content.data for content in tag.childNodes]
data[tag.tagName] = contents
return data

Expand Down

0 comments on commit d7708e1

Please sign in to comment.