Skip to content

Commit

Permalink
MAINT: Add wrapper function for PendingDeprecationWarnings (#928)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Peveler <[email protected]>
  • Loading branch information
MasterOdin authored Jun 1, 2022
1 parent 1d14a86 commit 5730198
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 884 deletions.
34 changes: 7 additions & 27 deletions PyPDF2/_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

import warnings
from io import BytesIO, FileIO, IOBase
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union, cast

from ._page import PageObject
from ._reader import PdfReader
from ._utils import DEPR_MSG, StrByteType, str_
from ._utils import deprecate_with_replacement, StrByteType, str_
from ._writer import PdfWriter
from .constants import PagesAttributes as PA
from .generic import (
Expand Down Expand Up @@ -321,9 +320,7 @@ def addMetadata(self, infos: Dict[str, Any]) -> None:
Use :meth:`add_metadata` instead.
"""
warnings.warn(
DEPR_MSG.format("addMetadata", "add_metadata"), PendingDeprecationWarning
)
deprecate_with_replacement("addMetadata", "add_metadata")
self.add_metadata(infos)

def setPageLayout(self, layout: LayoutType) -> None:
Expand All @@ -332,11 +329,7 @@ def setPageLayout(self, layout: LayoutType) -> None:
Use :meth:`set_page_layout` instead.
"""
warnings.warn(
DEPR_MSG.format("setPageLayout", "set_page_layout"),
PendingDeprecationWarning,
stacklevel=2,
)
deprecate_with_replacement("setPageLayout", "set_page_layout")
self.set_page_layout(layout)

def set_page_layout(self, layout: LayoutType) -> None:
Expand Down Expand Up @@ -373,9 +366,7 @@ def setPageMode(self, mode: PagemodeType) -> None:
Use :meth:`set_page_mode` instead.
"""
warnings.warn(
DEPR_MSG.format("setPageMode", "set_page_mode"), PendingDeprecationWarning
)
deprecate_with_replacement("setPageMode", "set_page_mode")
self.set_page_mode(mode)

def set_page_mode(self, mode: PagemodeType) -> None:
Expand Down Expand Up @@ -639,10 +630,7 @@ def addBookmark(
.. deprecated:: 1.28.0
Use :meth:`add_bookmark` instead.
"""
warnings.warn(
"addBookmark is deprecated. Use add_bookmark instead.",
DeprecationWarning,
)
deprecate_with_replacement("addBookmark", "add_bookmark")
return self.add_bookmark(
title, pagenum, parent, color, bold, italic, fit, *args
)
Expand Down Expand Up @@ -735,10 +723,7 @@ def addNamedDestination(self, title: str, pagenum: int) -> None:
.. deprecated:: 1.28.0
Use :meth:`add_named_destination` instead.
"""
warnings.warn(
"addNamedDestination is deprecated. Use add_named_destination instead.",
DeprecationWarning,
)
deprecate_with_replacement("addNamedDestination", "add_named_destination")
return self.add_named_destination(title, pagenum)

def add_named_destination(self, title: str, pagenum: int) -> None:
Expand All @@ -760,13 +745,8 @@ def add_named_destination(self, title: str, pagenum: int) -> None:

class PdfFileMerger(PdfMerger):
def __init__(self, *args: Any, **kwargs: Any) -> None:
import warnings
deprecate_with_replacement("PdfFileMerger", "PdfMerge")

warnings.warn(
"PdfFileMerger was renamed to PdfMerger. PdfFileMerger will be removed",
PendingDeprecationWarning,
stacklevel=2,
)
if "strict" not in kwargs and len(args) < 1:
kwargs["strict"] = True # maintain the default
super().__init__(*args, **kwargs)
Loading

0 comments on commit 5730198

Please sign in to comment.