In Python 3, if pypdfChr() is provided an input that is either a bytes or str object it will throw a TypeError.
And in Python 2, if pypdfChr() is provided an int or unicode object it will quietly return the same object type (int or unicode).
This is a problem because code that interacts with a bytes string in a loop, or accesses a bytes string by index, the individual character will be a str in Python 2 but an int in Python 3. And if the string type is not 100% known (that is, perhaps it's unicode in Python 2 or str in Python 3), then the same loop or index-based access may be passed into pypdfChr(), causing a crash or an incorrect type to be returned.
In Python 3, if
pypdfChr()
is provided an input that is either abytes
orstr
object it will throw a TypeError.And in Python 2, if
pypdfChr()
is provided anint
orunicode
object it will quietly return the same object type (int
orunicode
).This is a problem because code that interacts with a
bytes
string in a loop, or accesses abytes
string by index, the individual character will be astr
in Python 2 but anint
in Python 3. And if the string type is not 100% known (that is, perhaps it'sunicode
in Python 2 orstr
in Python 3), then the same loop or index-based access may be passed intopypdfChr()
, causing a crash or an incorrect type to be returned.