You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Importing anything from PyPDF2 now causes a deprecation warning to be raised as a result of #867. The root cause is that as part of importing PyPDF2.pagerange.PageRange a PageRange object is created, which calls isString. Here is a stack trace:
>>> from PyPDF2 import PdfReader
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/mpeveler/code/github/PyPDF2/PyPDF2/__init__.py", line 4, in <module>
from PyPDF2.merger import PdfFileMerger, PdfMerger
File "/Users/mpeveler/code/github/PyPDF2/PyPDF2/merger.py", line 35, in <module>
from PyPDF2.pagerange import PageRange
File "/Users/mpeveler/code/github/PyPDF2/PyPDF2/pagerange.py", line 128, in <module>
PAGE_RANGE_ALL = PageRange(":") # The range of all pages.
File "/Users/mpeveler/code/github/PyPDF2/PyPDF2/pagerange.py", line 74, in __init__
m = isString(arg) and re.match(PAGE_RANGE_RE, arg)
There is a number of other places where isString (and probably some other deprecated utils functions) is called as part of regular usage (e.g. in PdfReader constructor). To avoid these warnings as part of regular usage, I would suggest splitting each of these util functions in two as follows (using isString as an example):
def _isString(s):
return isinstance(s, _basestring)
def isString(s):
"""Test if arg is a string. Compatible with Python 2 and 3."""
warnings.warn(DEPR_MSG_NO_REPLACEMENT.format("isString"))
return _isString(s)
and change all internal usages of the function to _isString while leaving the user facing isString in place for downstream consumers to see the expected deprecation warning.
Environment
Which environment were you using when you encountered the problem?
>>> from PyPDF2 import PdfReader
/Users/mpeveler/code/github/PyPDF2/PyPDF2/_utils.py:72: UserWarning: isString is deprecated and will be removed in PyPDF2 2.0.0.
warnings.warn(DEPR_MSG_NO_REPLACEMENT.format("isString"))
The text was updated successfully, but these errors were encountered:
MasterOdin
added
the
is-bug
From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF
label
May 22, 2022
Some other basic usage triggering these deprecation warnings:
>>> pageObject = a.pages[0]
UserWarning: ConvertFunctionsToVirtualList is deprecated and will be removed in PyPDF2 2.0.0. [_utils.py:171]
UserWarning: isInt is deprecated and will be removed in PyPDF2 2.0.0. [_utils.py:78]
Thank you for all of the information and testing it so quickly! Yes, splitting the function isString into isString + one that does not trigger a warning is an excellent idea 👍 (although I would prefer _is_string - but I'd accept either version in a PR 😄 ).
Importing anything from PyPDF2 now causes a deprecation warning to be raised as a result of #867. The root cause is that as part of importing
PyPDF2.pagerange.PageRange
aPageRange
object is created, which callsisString
. Here is a stack trace:There is a number of other places where
isString
(and probably some other deprecated utils functions) is called as part of regular usage (e.g. inPdfReader
constructor). To avoid these warnings as part of regular usage, I would suggest splitting each of these util functions in two as follows (usingisString
as an example):and change all internal usages of the function to
_isString
while leaving the user facingisString
in place for downstream consumers to see the expected deprecation warning.Environment
Which environment were you using when you encountered the problem?
Code
The text was updated successfully, but these errors were encountered: