From 755df8f4b6fd6bf1cb347e3b798f4c12d84c4abf Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Sat, 19 Aug 2023 16:15:46 +0200 Subject: [PATCH] MAINT: Remove unnecessary decorator + mypy fixes While on it, pre-commit was also updated Taken from https://github.com/py-pdf/pypdf/pull/2086 Co-authored-by: Lucas Cimon <925560+Lucas-C@users.noreply.github.com> --- .pre-commit-config.yaml | 10 +++++----- pypdf/filters.py | 2 +- pypdf/generic/_data_structures.py | 10 +--------- pyproject.toml | 3 +++ tests/test_generic.py | 2 +- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dd3f32cb5..546a42b8f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,29 +27,29 @@ repos: - id: black args: [--target-version, py36] - repo: https://github.com/asottile/blacken-docs - rev: 1.15.0 + rev: 1.16.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.280' + rev: 'v0.0.285' hooks: - id: ruff args: ['--fix'] - repo: https://github.com/asottile/pyupgrade - rev: v3.9.0 + rev: v3.10.1 hooks: - id: pyupgrade args: [--py36-plus] - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 + rev: 6.1.0 hooks: - id: flake8 args: ["--ignore", "E,W,F"] - repo: https://github.com/pre-commit/mirrors-mypy - rev: 'v1.4.1' + rev: 'v1.5.1' hooks: - id: mypy files: ^pypdf/.* diff --git a/pypdf/filters.py b/pypdf/filters.py index 303838114..a90e5651b 100644 --- a/pypdf/filters.py +++ b/pypdf/filters.py @@ -656,7 +656,7 @@ def decode( return tiff_header + data -def decode_stream_data(stream: Any) -> Union[str, bytes]: # utils.StreamObject +def decode_stream_data(stream: Any) -> bytes: # utils.StreamObject """ Decode the stream data based on the specified filters. diff --git a/pypdf/generic/_data_structures.py b/pypdf/generic/_data_structures.py index 03cd848f5..08e156a5c 100644 --- a/pypdf/generic/_data_structures.py +++ b/pypdf/generic/_data_structures.py @@ -785,7 +785,7 @@ def _reset_node_tree_relationship(child_obj: Any) -> None: class StreamObject(DictionaryObject): def __init__(self) -> None: - self.__data: Optional[str] = None + self._data: bytes = b"" self.decoded_self: Optional[DecodedStreamObject] = None def _clone( @@ -833,14 +833,6 @@ def decodedSelf(self, value: "DecodedStreamObject") -> None: # deprecated deprecation_with_replacement("decodedSelf", "decoded_self", "3.0.0") self.decoded_self = value - @property - def _data(self) -> Any: - return self.__data - - @_data.setter - def _data(self, value: Any) -> None: - self.__data = value - def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] = None ) -> None: diff --git a/pyproject.toml b/pyproject.toml index da821b5f2..efbf681b0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -194,6 +194,9 @@ ignore = [ "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 + "PYI042", # Type alias `mode_str_type` should be CamelCase + # Ruff bug + "PT014", # Duplicate of test case at index 1 in `@pytest_mark.parametrize` ] [tool.ruff.per-file-ignores] diff --git a/tests/test_generic.py b/tests/test_generic.py index fe91b7184..bdb244abc 100644 --- a/tests/test_generic.py +++ b/tests/test_generic.py @@ -426,7 +426,7 @@ class Tst: # to replace pdf # TODO: What should happen with the stream? assert do == {"/S": "/GoTo"} if length in (6, 10): - assert b"BT /F1" in do._StreamObject__data + assert b"BT /F1" in do._data raise PdfReadError("__ALLGOOD__") assert should_fail ^ (exc.value.args[0] == "__ALLGOOD__")