Skip to content

Commit 0b58493

Browse files
MAINT: Cleanup deprecations (#3424)
The encryption key cannot be removed yet as this requires changing the method signature everywhere, but we have deprecations for two different pypdf versions.
1 parent 794504b commit 0b58493

18 files changed

+60
-400
lines changed

pypdf/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from ._crypt_providers import crypt_provider
1111
from ._doc_common import DocumentInformation
1212
from ._encryption import PasswordType
13-
from ._merger import PdfMerger
1413
from ._page import PageObject, Transformation
1514
from ._reader import PdfReader
1615
from ._text_extraction import mult
@@ -39,7 +38,6 @@
3938
"PageRange",
4039
"PaperSize",
4140
"PasswordType",
42-
"PdfMerger",
4341
"PdfReader",
4442
"PdfWriter",
4543
"Transformation",

pypdf/_doc_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from ._page import PageObject, _VirtualList
4545
from ._page_labels import index2label as page_index2page_label
4646
from ._utils import (
47-
deprecate_with_replacement,
47+
deprecation_with_replacement,
4848
logger_warning,
4949
parse_iso8824_date,
5050
)
@@ -1259,7 +1259,7 @@ def decode_permissions(
12591259
self, permissions_code: int
12601260
) -> dict[str, bool]: # pragma: no cover
12611261
"""Take the permissions as an integer, return the allowed access."""
1262-
deprecate_with_replacement(
1262+
deprecation_with_replacement(
12631263
old_name="decode_permissions",
12641264
new_name="user_access_permissions",
12651265
removed_in="5.0.0",

pypdf/_merger.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

pypdf/_writer.py

Lines changed: 3 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@
5858
StrByteType,
5959
StreamType,
6060
_get_max_pdf_version_header,
61-
deprecate,
62-
deprecate_no_replacement,
63-
deprecation_with_replacement,
61+
deprecation_no_replacement,
6462
logger_warning,
6563
)
6664
from .constants import AnnotationDictionaryAttributes as AA
@@ -377,12 +375,12 @@ def xmp_metadata(self, value: Optional[XmpInformation]) -> None:
377375

378376
@property
379377
def with_as_usage(self) -> bool:
380-
deprecate_no_replacement("with_as_usage", "6.0")
378+
deprecation_no_replacement("with_as_usage", "5.0")
381379
return self._with_as_usage
382380

383381
@with_as_usage.setter
384382
def with_as_usage(self, value: bool) -> None:
385-
deprecate_no_replacement("with_as_usage", "6.0")
383+
deprecation_no_replacement("with_as_usage", "5.0")
386384
self._with_as_usage = value
387385

388386
def __enter__(self) -> "PdfWriter":
@@ -1426,10 +1424,6 @@ def write_stream(self, stream: StreamType) -> None:
14261424
"It may not be written to correctly.",
14271425
__name__,
14281426
)
1429-
# deprecated to be removed in pypdf 6.0.0 :
1430-
# if not self._root:
1431-
# self._root = self._add_object(self._root_object)
1432-
# self._sweep_indirect_references(self._root)
14331427
self._resolve_links()
14341428

14351429
if self.incremental:
@@ -1754,74 +1748,6 @@ def replace_in_obj(
17541748
for i in compress(range(len(self._objects)), orphans):
17551749
self._objects[i] = None
17561750

1757-
def _sweep_indirect_references(
1758-
self,
1759-
root: Union[
1760-
ArrayObject,
1761-
BooleanObject,
1762-
DictionaryObject,
1763-
FloatObject,
1764-
IndirectObject,
1765-
NameObject,
1766-
PdfObject,
1767-
NumberObject,
1768-
TextStringObject,
1769-
NullObject,
1770-
],
1771-
) -> None: # deprecated
1772-
"""
1773-
Resolving any circular references to Page objects.
1774-
1775-
Circular references to Page objects can arise when objects such as
1776-
annotations refer to their associated page. If these references are not
1777-
properly handled, the PDF file will contain multiple copies of the same
1778-
Page object. To address this problem, Page objects store their original
1779-
object reference number. This method adds the reference number of any
1780-
circularly referenced Page objects to an external reference map. This
1781-
ensures that self-referencing trees reference the correct new object
1782-
location, rather than copying in a new copy of the Page object.
1783-
1784-
Args:
1785-
root: The root of the PDF object tree to sweep.
1786-
1787-
"""
1788-
deprecate(
1789-
"_sweep_indirect_references has been removed, please report to dev team if this warning is observed",
1790-
)
1791-
1792-
def _resolve_indirect_object(
1793-
self, data: IndirectObject
1794-
) -> IndirectObject: # deprecated
1795-
"""
1796-
Resolves an indirect object to an indirect object in this PDF file.
1797-
1798-
If the input indirect object already belongs to this PDF file, it is
1799-
returned directly. Otherwise, the object is retrieved from the input
1800-
object's PDF file using the object's ID number and generation number. If
1801-
the object cannot be found, a warning is logged and a `NullObject` is
1802-
returned.
1803-
1804-
If the object is not already in this PDF file, it is added to the file's
1805-
list of objects and assigned a new ID number and generation number of 0.
1806-
The hash value of the object is then added to the `_idnum_hash`
1807-
dictionary, with the corresponding `IndirectObject` reference as the
1808-
value.
1809-
1810-
Args:
1811-
data: The `IndirectObject` to resolve.
1812-
1813-
Returns:
1814-
The resolved `IndirectObject` in this PDF file.
1815-
1816-
Raises:
1817-
ValueError: If the input stream is closed.
1818-
1819-
"""
1820-
deprecate(
1821-
"_resolve_indirect_object has been removed, please report to dev team if this warning is observed",
1822-
)
1823-
return IndirectObject(0, 0, self)
1824-
18251751
def get_reference(self, obj: PdfObject) -> IndirectObject:
18261752
idnum = self._objects.index(obj) + 1
18271753
ref = IndirectObject(idnum, 0, self)
@@ -3255,17 +3181,6 @@ def find_outline_item(
32553181
else:
32563182
return None
32573183

3258-
def find_bookmark(
3259-
self,
3260-
outline_item: dict[str, Any],
3261-
root: Optional[OutlineType] = None,
3262-
) -> None: # deprecated
3263-
"""
3264-
.. deprecated:: 2.9.0
3265-
Use :meth:`find_outline_item` instead.
3266-
"""
3267-
deprecation_with_replacement("find_bookmark", "find_outline_item", "5.0.0")
3268-
32693184
def reset_translation(
32703185
self, reader: Union[None, PdfReader, IndirectObject] = None
32713186
) -> None:

pypdf/annotations/_markup_annotations.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from abc import ABC
33
from typing import Any, Optional, Union
44

5-
from .._utils import deprecation_with_replacement
65
from ..constants import AnnotationFlag
76
from ..generic import ArrayObject, DictionaryObject
87
from ..generic._base import (
@@ -217,10 +216,6 @@ def __init__(
217216
interior_color: Optional[str] = None,
218217
**kwargs: Any,
219218
) -> None:
220-
if "interiour_color" in kwargs:
221-
deprecation_with_replacement("interiour_color", "interior_color", "5.0.0")
222-
interior_color = kwargs["interiour_color"]
223-
del kwargs["interiour_color"]
224219
super().__init__(**kwargs)
225220
self.update(
226221
{
@@ -269,10 +264,6 @@ def __init__(
269264
interior_color: Optional[str] = None,
270265
**kwargs: Any,
271266
) -> None:
272-
if "interiour_color" in kwargs:
273-
deprecation_with_replacement("interiour_color", "interior_color", "5.0.0")
274-
interior_color = kwargs["interiour_color"]
275-
del kwargs["interiour_color"]
276267
super().__init__(**kwargs)
277268

278269
self.update(

pypdf/constants.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,6 @@ class Resources:
144144
PROPERTIES = "/Properties" # dictionary, optional
145145

146146

147-
class Ressources: # deprecated
148-
"""
149-
Use :class: `Resources` instead.
150-
151-
.. deprecated:: 5.0.0
152-
"""
153-
154-
155147
class PagesAttributes:
156148
"""§7.7.3.2 of the 1.7 and 2.0 reference."""
157149

pypdf/filters.py

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@
5050
from ._codecs._codecs import LzwCodec as _LzwCodec
5151
from ._utils import (
5252
WHITESPACES_AS_BYTES,
53-
deprecate,
54-
deprecate_with_replacement,
55-
deprecation_no_replacement,
53+
deprecation_with_replacement,
5654
logger_warning,
5755
)
5856
from .constants import CcittFaxDecodeParameters as CCITT
@@ -61,7 +59,7 @@
6159
from .constants import ImageAttributes as IA
6260
from .constants import LzwFilterParameters as LZW
6361
from .constants import StreamAttributes as SA
64-
from .errors import DependencyError, DeprecationError, PdfReadError, PdfStreamError
62+
from .errors import DependencyError, PdfReadError, PdfStreamError
6563
from .generic import (
6664
ArrayObject,
6765
BooleanObject,
@@ -145,9 +143,6 @@ def decode(
145143
PdfReadError:
146144
147145
"""
148-
if isinstance(decode_parms, ArrayObject):
149-
raise DeprecationError("decode_parms as ArrayObject is deprecated")
150-
151146
str_data = decompress(data)
152147
predictor = 1
153148

@@ -420,7 +415,7 @@ def decode(self) -> bytes:
420415
return _LzwCodec().decode(self.data)
421416

422417
@staticmethod
423-
def _decodeb(
418+
def decode(
424419
data: bytes,
425420
decode_parms: Optional[DictionaryObject] = None,
426421
**kwargs: Any,
@@ -439,27 +434,6 @@ def _decodeb(
439434
# decode_parms is unused here
440435
return LZWDecode.Decoder(data).decode()
441436

442-
@staticmethod
443-
def decode(
444-
data: bytes,
445-
decode_parms: Optional[DictionaryObject] = None,
446-
**kwargs: Any,
447-
) -> str: # deprecated
448-
"""
449-
Decode an LZW encoded data stream.
450-
451-
Args:
452-
data: ``bytes`` or ``str`` text to decode.
453-
decode_parms: a dictionary of parameter values.
454-
455-
Returns:
456-
decoded data.
457-
458-
"""
459-
# decode_parms is unused here
460-
deprecate("LZWDecode.decode will return bytes instead of str in pypdf 6.0.0")
461-
return LZWDecode.Decoder(data).decode().decode("latin-1")
462-
463437

464438
class ASCII85Decode:
465439
"""Decodes string ASCII85-encoded data into a byte format."""
@@ -568,7 +542,7 @@ def __create_old_class_instance(
568542
columns: int = 0,
569543
rows: int = 0
570544
) -> CCITTParameters:
571-
deprecate_with_replacement("CCITParameters", "CCITTParameters", "6.0.0")
545+
deprecation_with_replacement("CCITParameters", "CCITTParameters", "6.0.0")
572546
return CCITTParameters(K, columns, rows)
573547

574548

@@ -619,10 +593,6 @@ def decode(
619593
height: int = 0,
620594
**kwargs: Any,
621595
) -> bytes:
622-
if isinstance(decode_parms, ArrayObject): # deprecated
623-
deprecation_no_replacement(
624-
"decode_parms being an ArrayObject", removed_in="3.15.5"
625-
)
626596
params = CCITTFaxDecode._get_parameters(decode_parms, height)
627597

628598
img_size = len(data)
@@ -772,7 +742,7 @@ def decode_stream_data(stream: Any) -> bytes:
772742
elif filter_name in (FT.ASCII_85_DECODE, FTA.A85):
773743
data = ASCII85Decode.decode(data)
774744
elif filter_name in (FT.LZW_DECODE, FTA.LZW):
775-
data = LZWDecode._decodeb(data, params)
745+
data = LZWDecode.decode(data, params)
776746
elif filter_name in (FT.FLATE_DECODE, FTA.FL):
777747
data = FlateDecode.decode(data, params)
778748
elif filter_name in (FT.RUN_LENGTH_DECODE, FTA.RL):

0 commit comments

Comments
 (0)