Skip to content

Commit

Permalink
Remove deprecated parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Dec 24, 2023
1 parent 3d45f24 commit c64b5bb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 289 deletions.
75 changes: 4 additions & 71 deletions pypdf/_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
# 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 pathlib import Path
from types import TracebackType
Expand Down Expand Up @@ -124,12 +123,11 @@ def __exit__(
@deprecation_bookmark(bookmark="outline_item", import_bookmarks="import_outline")
def merge(
self,
page_number: Optional[int] = None,
fileobj: Union[None, Path, StrByteType, PdfReader] = None,
page_number: int,
fileobj: Union[Path, StrByteType, PdfReader],
outline_item: Optional[str] = None,
pages: Optional[PageRangeSpec] = None,
import_outline: bool = True,
position: Optional[int] = None, # deprecated
) -> None:
"""
Merge the pages from the given file into the output file at the
Expand All @@ -154,33 +152,6 @@ def merge(
outline (collection of outline items, previously referred to as
'bookmarks') from being imported by specifying this as ``False``.
"""
if position is not None: # deprecated
if page_number is None:
page_number = position
old_term = "position"
new_term = "page_number"
warnings.warn(
(
f"{old_term} is deprecated as an argument and will be "
f"removed in pypdf=4.0.0. Use {new_term} instead"
),
DeprecationWarning,
)
else:
raise ValueError(
"The argument position of merge is deprecated. "
"Use page_number only."
)

if page_number is None: # deprecated
# The parameter is only marked as Optional as long as
# position is not fully deprecated
raise ValueError("page_number may not be None")
if fileobj is None: # deprecated
# The argument is only Optional due to the deprecated position
# argument
raise ValueError("fileobj may not be None")

stream, encryption_obj = self._create_stream(fileobj)

# Create a new PdfReader instance using the stream
Expand Down Expand Up @@ -641,13 +612,12 @@ def find_bookmark(
def add_outline_item(
self,
title: str,
page_number: Optional[int] = None,
page_number: int,
parent: Union[None, TreeObject, IndirectObject] = None,
color: Optional[Tuple[float, float, float]] = None,
bold: bool = False,
italic: bool = False,
fit: Fit = PAGE_FIT,
pagenum: Optional[int] = None, # deprecated
) -> IndirectObject:
"""
Add an outline item (commonly referred to as a "Bookmark") to this PDF file.
Expand All @@ -663,24 +633,6 @@ def add_outline_item(
italic: Outline item font is italic
fit: The fit of the destination page.
"""
if page_number is not None and pagenum is not None:
raise ValueError(
"The argument pagenum of add_outline_item is deprecated. "
"Use page_number only."
)
if pagenum is not None: # deprecated
old_term = "pagenum"
new_term = "page_number"
warnings.warn(
(
f"{old_term} is deprecated as an argument and will be "
f"removed in pypdf==4.0.0. Use {new_term} instead"
),
DeprecationWarning,
)
page_number = pagenum
if page_number is None: # deprecated
raise ValueError("page_number may not be None")
writer = self.output
if writer is None:
raise RuntimeError(ERR_CLOSED_WRITER)
Expand All @@ -698,8 +650,7 @@ def add_outline_item(
def add_named_destination(
self,
title: str,
page_number: Optional[int] = None,
pagenum: Optional[int] = None,
page_number: int,
) -> None:
"""
Add a destination to the output.
Expand All @@ -708,24 +659,6 @@ def add_named_destination(
title: Title to use
page_number: Page number this destination points at.
"""
if page_number is not None and pagenum is not None:
raise ValueError(
"The argument pagenum of add_named_destination is deprecated. "
"Use page_number only."
)
if pagenum is not None: # deprecated
old_term = "pagenum"
new_term = "page_number"
warnings.warn(
(
f"{old_term} is deprecated as an argument and will be "
f"removed in pypdf==4.0.0. Use {new_term} instead"
),
DeprecationWarning,
)
page_number = pagenum
if page_number is None: # deprecated
raise ValueError("page_number may not be None")
dest = Destination(
TextStringObject(title),
NumberObject(page_number),
Expand Down
27 changes: 0 additions & 27 deletions pypdf/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,41 +322,14 @@ def __init__(
self,
pdf: Union[None, PdfReaderProtocol, PdfWriterProtocol] = None,
indirect_reference: Optional[IndirectObject] = None,
indirect_ref: Optional[IndirectObject] = None, # deprecated
) -> None:
DictionaryObject.__init__(self)
self.pdf: Union[None, PdfReaderProtocol, PdfWriterProtocol] = pdf
self.inline_images: Optional[Dict[str, ImageFile]] = None
# below Union for mypy but actually Optional[List[str]]
self.inline_images_keys: Optional[List[Union[str, List[str]]]] = None
if indirect_ref is not None: # deprecated
warnings.warn(
(
"indirect_ref is deprecated and will be removed in "
"pypdf 4.0.0. Use indirect_reference instead of indirect_ref."
),
DeprecationWarning,
)
if indirect_reference is not None:
raise ValueError("Use indirect_reference instead of indirect_ref.")
indirect_reference = indirect_ref
self.indirect_reference = indirect_reference

@property
def indirect_ref(self) -> Optional[IndirectObject]: # deprecated
warnings.warn(
(
"indirect_ref is deprecated and will be removed in pypdf 4.0.0"
"Use indirect_reference instead of indirect_ref."
),
DeprecationWarning,
)
return self.indirect_reference

@indirect_ref.setter
def indirect_ref(self, value: Optional[IndirectObject]) -> None: # deprecated
self.indirect_reference = value

def hash_value_data(self) -> bytes:
data = super().hash_value_data()
data += b"%d" % id(self)
Expand Down
Loading

0 comments on commit c64b5bb

Please sign in to comment.