Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: Adjust deprecation messages #919

Merged
merged 4 commits into from
May 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions PyPDF2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._merger import PdfMerger
from ._merger import PdfFileMerger, PdfMerger
from ._page import Transformation
from ._reader import DocumentInformation, PdfFileReader, PdfReader
from ._version import __version__
Expand All @@ -12,9 +12,9 @@
"PaperSize",
"DocumentInformation",
"parse_filename_page_ranges",
"PdfFileMerger", # will be removed soon; use PdfMerger instead
"PdfFileReader", # will be removed soon; use PdfReader instead
"PdfFileWriter", # will be removed soon; use PdfWriter instead
"PdfFileMerger", # will be removed in PyPDF2 3.0.0; use PdfMerger instead
"PdfFileReader", # will be removed in PyPDF2 3.0.0; use PdfReader instead
"PdfFileWriter", # will be removed in PyPDF2 3.0.0; use PdfWriter instead
"PdfMerger",
"Transformation",
"PdfReader",
Expand Down
6 changes: 4 additions & 2 deletions PyPDF2/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,10 @@ def mergeTransformedPage(
Use :meth:`add_transformation` and :meth:`merge_page` instead.
"""
warnings.warn(
"page.mergeTransformedPage(page2, ctm) will be removed in PyPDF 2.0.0. "
"Use page2.add_transformation(ctm); page.merge_page(page2) instead.",
DEPR_MSG.format(
"page.mergeTransformedPage(page2, ctm)",
"page2.add_transformation(ctm); page.merge_page(page2)",
),
PendingDeprecationWarning,
stacklevel=2,
)
Expand Down
87 changes: 40 additions & 47 deletions PyPDF2/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
from ._page import PageObject, _VirtualList
from ._security import RC4_encrypt, _alg33_1, _alg34, _alg35
from ._utils import (
DEPR_MSG,
DEPR_MSG_NO_REPLACEMENT,
StrByteType,
StreamType,
b_,
Expand Down Expand Up @@ -102,8 +104,7 @@ def convert_to_int(d: bytes, size: int) -> Union[int, Tuple[Any, ...]]:

def convertToInt(d: bytes, size: int) -> Union[int, Tuple[Any, ...]]:
warnings.warn(
"convertToInt will be removed with PyPDF2 2.0.0. "
"Use convert_to_int instead.",
DEPR_MSG.format("convertToInt", "convert_to_int"),
PendingDeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -142,7 +143,7 @@ def getText(self, key: str) -> Optional[str]:
Use the attributes (e.g. :py:attr:`title` / :py:attr:`author`).
"""
warnings.warn(
"getText will be removed in PyPDF2 2.0.0.",
DEPR_MSG_NO_REPLACEMENT.format("getText"),
PendingDeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -281,7 +282,7 @@ def getDocumentInfo(self) -> Optional[DocumentInformation]:
"""
warnings.warn(
"The `getDocumentInfo` method of PdfReader will be replaced by the "
"`metadata` attribute in PyPDF2 2.0.0. You can switch to the "
"`metadata` attribute in PyPDF2 3.0.0. You can switch to the "
"metadata attribute already.",
PendingDeprecationWarning,
stacklevel=2,
Expand All @@ -297,7 +298,7 @@ def documentInfo(self) -> Optional[DocumentInformation]:
"""
warnings.warn(
"The `documentInfo` attribute of PdfReader will be replaced by "
"`metadata` in PyPDF2 2.0.0. You can switch to the metadata "
"`metadata` in PyPDF2 3.0.0. You can switch to the metadata "
"attribute already.",
PendingDeprecationWarning,
stacklevel=2,
Expand Down Expand Up @@ -328,7 +329,7 @@ def getXmpMetadata(self) -> Optional[XmpInformation]:
"""
warnings.warn(
"The `getXmpMetadata` method of PdfReader will be replaced by the "
"`xmp_metadata` attribute in PyPDF2 2.0.0. You can switch to the "
"`xmp_metadata` attribute in PyPDF2 3.0.0. You can switch to the "
"xmp_metadata attribute already.",
PendingDeprecationWarning,
stacklevel=2,
Expand All @@ -344,7 +345,7 @@ def xmpMetadata(self) -> Optional[XmpInformation]:
"""
warnings.warn(
"The `xmpMetadata` attribute of PdfReader will be replaced by the "
"`xmp_metadata` attribute in PyPDF2 2.0.0. You can switch to the "
"`xmp_metadata` attribute in PyPDF2 3.0.0. You can switch to the "
"xmp_metadata attribute already.",
PendingDeprecationWarning,
stacklevel=2,
Expand Down Expand Up @@ -385,8 +386,7 @@ def getNumPages(self) -> int:
Use :code:`len(reader.pages)` instead.
"""
warnings.warn(
"The `getNumPages` method of PdfReader will be removed in PyPDF2 2.0.0. "
"Use `len(reader.pages)` instead.",
DEPR_MSG.format("reader.getNumPages", "len(reader.pages)"),
PendingDeprecationWarning,
stacklevel=2,
)
Expand All @@ -400,7 +400,7 @@ def numPages(self) -> int:
Use :code:`len(reader.pages)` instead.
"""
warnings.warn(
"The `numPages` attribute of PdfReader will be removed in PyPDF2 2.0.0. "
"The `numPages` attribute of PdfReader will be removed in PyPDF2 3.0.0. "
"Use `len(reader.pages)` instead.",
PendingDeprecationWarning,
stacklevel=2,
Expand All @@ -414,8 +414,7 @@ def getPage(self, pageNumber: int) -> PageObject:
Use :code:`reader.pages[pageNumber]` instead.
"""
warnings.warn(
"`getPage` of PdfReader will be removed in PyPDF2 2.0.0. "
"Use `reader.pages[pageNumber]` instead.",
DEPR_MSG.format("reader.getPage(pageNumber)", "reader.pages[pageNumber]"),
PendingDeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -445,8 +444,7 @@ def namedDestinations(self) -> Dict[str, Any]:
Use :py:attr:`named_destinations` instead.
"""
warnings.warn(
"namedDestinations will be removed in PyPDF2 2.0.0. "
"Use `named_destinations` instead.",
DEPR_MSG.format("reader.namedDestinations", "reader.named_destinations"),
PendingDeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -528,8 +526,7 @@ def getFields(
Use :meth:`get_fields` instead.
"""
warnings.warn(
"The getFields method of PdfReader will be removed in PyPDF2 2.0.0. "
"Use the get_fields() method instead.",
DEPR_MSG.format("reader.getFields", "reader.get_fields"),
PendingDeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -611,8 +608,7 @@ def getFormTextFields(self) -> Dict[str, Any]:
Use :meth:`get_form_text_fields` instead.
"""
warnings.warn(
"The getFormTextFields method of PdfReader will be removed in PyPDF2 2.0.0. "
"Use the get_form_text_fields() method instead.",
DEPR_MSG.format("reader.getFormTextFields", "reader.get_form_text_fields"),
PendingDeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -675,8 +671,7 @@ def getNamedDestinations(
Use :py:attr:`named_destinations` instead.
"""
warnings.warn(
"getNamedDestinations will be removed in PyPDF2 2.0.0. "
"Use the named_destinations property instead.",
DEPR_MSG.format("reader.getNamedDestinations", "reader.named_destinations"),
PendingDeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -744,7 +739,7 @@ def getOutlines(
Use :py:attr:`outlines` instead.
"""
warnings.warn(
"getOutlines will be removed in PyPDF2 2.0.0. Use the outlines attribute instead.",
DEPR_MSG.format("reader.getOutlines", "reader.outlines"),
PendingDeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -788,8 +783,9 @@ def getPageNumber(self, page: PageObject) -> int:
Use :meth:`get_page_number` instead.
"""
warnings.warn(
"getPageNumber will be removed in PyPDF2 2.0.0. "
"Use get_page_number instead.",
DEPR_MSG.format(
"reader.getPageNumber(page)", "reader.get_page_number(page)"
),
PendingDeprecationWarning,
stacklevel=2,
)
Expand All @@ -812,8 +808,9 @@ def getDestinationPageNumber(self, destination: Destination) -> int:
Use :meth:`get_destination_page_number` instead.
"""
warnings.warn(
"getDestinationPageNumber will be removed in PyPDF2 2.0.0. "
"Use get_destination_page_number instead.",
DEPR_MSG.format(
"reader.getDestinationPageNumber", "reader.get_destination_page_number"
),
PendingDeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -909,8 +906,7 @@ def getPageLayout(self) -> Optional[str]:
Use :py:attr:`page_layout` instead.
"""
warnings.warn(
"getPageLayout will be removed in PyPDF2 2.0.0. "
"Use the attribute 'page_layout' instead.",
DEPR_MSG.format("reader.getPageLayout()", "reader.page_layout"),
PendingDeprecationWarning,
stacklevel=2,
)
Expand All @@ -924,8 +920,7 @@ def pageLayout(self) -> Optional[str]:
Use :py:attr:`page_layout` instead.
"""
warnings.warn(
"pageLayout will be removed in PyPDF2 2.0.0. "
"Use the attribute 'page_layout' instead.",
DEPR_MSG.format("reader.pageLayout", "reader.page_layout"),
PendingDeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -967,8 +962,7 @@ def getPageMode(self) -> Optional[PagemodeType]:
Use :py:attr:`page_mode` instead.
"""
warnings.warn(
"getPageMode will be removed in PyPDF2 2.0.0. "
"Use the attribute 'page_mode' instead.",
DEPR_MSG.format("reader.getPageMode()", "reader.page_mode"),
PendingDeprecationWarning,
stacklevel=2,
)
Expand All @@ -982,8 +976,7 @@ def pageMode(self) -> Optional[PagemodeType]:
Use :py:attr:`page_mode` instead.
"""
warnings.warn(
"pageMode will be removed in PyPDF2 2.0.0. "
"Use the attribute 'page_mode' instead.",
DEPR_MSG.format("reader.pageMode", "reader.page_mode"),
PendingDeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -1163,8 +1156,10 @@ def getObject(self, indirectReference: IndirectObject) -> Optional[PdfObject]:
Use :meth:`get_object` instead.
"""
warnings.warn(
"getObject(indirectReference) will be removed in PyPDF2 2.0.0. "
"Use get_object(indirect_reference) instead.",
DEPR_MSG.format(
"reader.getObject(indirectReference)",
"reader.get_object(indirect_reference)",
),
PendingDeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -1235,8 +1230,7 @@ def readObjectHeader(self, stream: StreamType) -> Tuple[int, int]:
Use :meth:`read_object_header` instead.
"""
warnings.warn(
"readObjectHeader will be removed with PyPDF2 2.0.0. "
"Use read_object_header instead.",
DEPR_MSG.format("reader.readObjectHeader", "reader.read_object_header"),
PendingDeprecationWarning,
stacklevel=2,
)
Expand All @@ -1256,8 +1250,9 @@ def cacheGetIndirectObject(
Use :meth:`cache_get_indirect_object` instead.
"""
warnings.warn(
"cacheGetIndirectObject will be removed with PyPDF2 2.0.0. "
"Use cache_get_indirect_object instead.",
DEPR_MSG.format(
"reader.cacheGetIndirectObject", "reader.cache_get_indirect_object"
),
PendingDeprecationWarning,
stacklevel=2,
)
Expand All @@ -1284,8 +1279,9 @@ def cacheIndirectObject(
Use :meth:`cache_indirect_object` instead.
"""
warnings.warn(
"cacheIndirectObject will be removed with PyPDF2 2.0.0. "
"Use cache_indirect_object instead.",
DEPR_MSG.format(
"reader.cacheIndirectObject", "reader.cache_indirect_object"
),
PendingDeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -1679,8 +1675,7 @@ def readNextEndLine(self, stream: StreamType, limit_offset: int = 0) -> bytes:
Use :meth:`read_next_end_line` instead.
"""
warnings.warn(
"readNextEndLine will be removed in PyPDF2 2.0.0. "
"Use read_next_end_line instead.",
DEPR_MSG.format("reader.readNextEndLine", "reader.read_next_end_line"),
PendingDeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -1833,8 +1828,7 @@ def getIsEncrypted(self) -> bool:
Use :py:attr:`is_encrypted` instead.
"""
warnings.warn(
"getIsEncrypted() will be removed in PyPDF2 2.0.0. "
"Use the is_encrypted property instead.",
DEPR_MSG.format("reader.getIsEncrypted()", "reader.is_encrypted"),
PendingDeprecationWarning,
stacklevel=2,
)
Expand All @@ -1848,8 +1842,7 @@ def isEncrypted(self) -> bool:
Use :py:attr:`is_encrypted` instead.
"""
warnings.warn(
"isEncrypted will be removed in PyPDF2 2.0.0. "
"Use the is_encrypted property instead.",
DEPR_MSG.format("reader.isEncrypted", "reader.is_encrypted"),
PendingDeprecationWarning,
stacklevel=2,
)
Expand Down
4 changes: 2 additions & 2 deletions PyPDF2/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
StreamType = Union[BytesIO, BufferedReader, BufferedWriter, FileIO]
StrByteType = Union[str, StreamType]

DEPR_MSG_NO_REPLACEMENT = "{} is deprecated and will be removed in PyPDF2 2.0.0."
DEPR_MSG = "{} is deprecated and will be removed in PyPDF2 2.0.0. Use {} instead."
DEPR_MSG_NO_REPLACEMENT = "{} is deprecated and will be removed in PyPDF2 3.0.0."
DEPR_MSG = "{} is deprecated and will be removed in PyPDF2 3.0.0. Use {} instead."


def read_until_whitespace(stream: StreamType, maxchars: Optional[int] = None) -> bytes:
Expand Down
Loading