Skip to content

Commit

Permalink
MAINT: Remove deprecated code
Browse files Browse the repository at this point in the history
Also don't use a default for the deprecation functions.
If the version is mentioned explicitly with every call, we can
more easily search for it.
  • Loading branch information
MartinThoma committed Dec 24, 2023
1 parent 54a30cb commit 0827dd5
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 1,701 deletions.
9 changes: 3 additions & 6 deletions pypdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

from ._crypt_providers import crypt_provider
from ._encryption import PasswordType
from ._merger import PdfFileMerger, PdfMerger
from ._merger import PdfMerger
from ._page import PageObject, Transformation, mult
from ._reader import DocumentInformation, PdfFileReader, PdfReader
from ._reader import DocumentInformation, PdfReader
from ._version import __version__
from ._writer import ObjectDeletionFlag, PdfFileWriter, PdfWriter
from ._writer import ObjectDeletionFlag, PdfWriter
from .constants import ImageType
from .pagerange import PageRange, parse_filename_page_ranges
from .papersizes import PaperSize
Expand All @@ -39,9 +39,6 @@
"DocumentInformation",
"ObjectDeletionFlag",
"parse_filename_page_ranges",
"PdfFileMerger", # will be removed in pypdf==4.0.0; use PdfMerger instead
"PdfFileReader", # will be removed in pypdf==4.0.0; use PdfReader instead
"PdfFileWriter", # will be removed in pypdf==4.0.0; use PdfWriter instead
"PdfMerger",
"PdfReader",
"PdfWriter",
Expand Down
101 changes: 1 addition & 100 deletions pypdf/_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
StrByteType,
deprecate_with_replacement,
deprecation_bookmark,
deprecation_with_replacement,
str_,
)
from ._writer import PdfWriter
Expand All @@ -70,7 +69,7 @@
TreeObject,
)
from .pagerange import PageRange, PageRangeSpec
from .types import FitType, LayoutType, OutlineType, PagemodeType, ZoomArgType
from .types import LayoutType, OutlineType, PagemodeType

ERR_CLOSED_WRITER = "close() was called and thus the writer cannot be used anymore"

Expand Down Expand Up @@ -360,24 +359,6 @@ def add_metadata(self, infos: Dict[str, Any]) -> None:
raise RuntimeError(ERR_CLOSED_WRITER)
self.output.add_metadata(infos)

def addMetadata(self, infos: Dict[str, Any]) -> None: # deprecated
"""
Use :meth:`add_metadata` instead.
.. deprecated:: 1.28.0
"""
deprecation_with_replacement("addMetadata", "add_metadata")
self.add_metadata(infos)

def setPageLayout(self, layout: LayoutType) -> None: # deprecated
"""
Use :meth:`set_page_layout` instead.
.. deprecated:: 1.28.0
"""
deprecation_with_replacement("setPageLayout", "set_page_layout")
self.set_page_layout(layout)

def set_page_layout(self, layout: LayoutType) -> None:
"""
Set the page layout.
Expand Down Expand Up @@ -407,15 +388,6 @@ def set_page_layout(self, layout: LayoutType) -> None:
raise RuntimeError(ERR_CLOSED_WRITER)
self.output._set_page_layout(layout)

def setPageMode(self, mode: PagemodeType) -> None: # deprecated
"""
Use :meth:`set_page_mode` instead.
.. deprecated:: 1.28.0
"""
deprecation_with_replacement("setPageMode", "set_page_mode", "3.0.0")
self.set_page_mode(mode)

def set_page_mode(self, mode: PagemodeType) -> None:
"""
Set the page mode.
Expand Down Expand Up @@ -723,68 +695,6 @@ def add_outline_item(
fit,
)

def addBookmark(
self,
title: str,
pagenum: int, # deprecated, but the whole method is deprecated
parent: Union[None, TreeObject, IndirectObject] = None,
color: Optional[Tuple[float, float, float]] = None,
bold: bool = False,
italic: bool = False,
fit: FitType = "/Fit",
*args: ZoomArgType,
) -> IndirectObject: # deprecated
"""
.. deprecated:: 1.28.0
Use :meth:`add_outline_item` instead.
"""
deprecation_with_replacement("addBookmark", "add_outline_item", "3.0.0")
return self.add_outline_item(
title,
pagenum,
parent,
color,
bold,
italic,
Fit(fit_type=fit, fit_args=args),
)

def add_bookmark(
self,
title: str,
pagenum: int, # deprecated, but the whole method is deprecated already
parent: Union[None, TreeObject, IndirectObject] = None,
color: Optional[Tuple[float, float, float]] = None,
bold: bool = False,
italic: bool = False,
fit: FitType = "/Fit",
*args: ZoomArgType,
) -> IndirectObject: # deprecated
"""
.. deprecated:: 2.9.0
Use :meth:`add_outline_item` instead.
"""
deprecation_with_replacement("addBookmark", "add_outline_item", "3.0.0")
return self.add_outline_item(
title,
pagenum,
parent,
color,
bold,
italic,
Fit(fit_type=fit, fit_args=args),
)

def addNamedDestination(self, title: str, pagenum: int) -> None: # deprecated
"""
.. deprecated:: 1.28.0
Use :meth:`add_named_destination` instead.
"""
deprecation_with_replacement(
"addNamedDestination", "add_named_destination", "3.0.0"
)
return self.add_named_destination(title, pagenum)

def add_named_destination(
self,
title: str,
Expand Down Expand Up @@ -822,12 +732,3 @@ def add_named_destination(
Fit.fit_horizontally(top=826),
)
self.named_dests.append(dest)


class PdfFileMerger(PdfMerger): # deprecated
def __init__(self, *args: Any, **kwargs: Any) -> None:
deprecation_with_replacement("PdfFileMerger", "PdfMerger", "3.0.0")

if "strict" not in kwargs and len(args) < 1:
kwargs["strict"] = True # maintain the default
super().__init__(*args, **kwargs)
Loading

0 comments on commit 0827dd5

Please sign in to comment.