Skip to content

Commit

Permalink
MAINT: Remove catching OverflowException (#1302)
Browse files Browse the repository at this point in the history
Since Python 2.2 (PEP 237), integers cannot throw overflow exceptions.
  • Loading branch information
MartinThoma committed Aug 29, 2022
1 parent b5dce26 commit d9ba817
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
5 changes: 1 addition & 4 deletions PyPDF2/generic/_base.py
Expand Up @@ -272,10 +272,7 @@ class NumberObject(int, PdfObject):

def __new__(cls, value: Any) -> "NumberObject":
val = int(value)
try:
return int.__new__(cls, val)
except OverflowError:
return int.__new__(cls, 0)
return int.__new__(cls, val)

def as_numeric(self) -> int:
return int(repr(self).encode("utf8"))
Expand Down
5 changes: 2 additions & 3 deletions tests/test_generic.py
Expand Up @@ -43,9 +43,8 @@ def test_float_object_exception():
assert FloatObject("abc") == 0


def test_number_object_exception():
with pytest.raises(OverflowError):
NumberObject(1.5 * 2**10000)
def test_number_object_no_exception():
NumberObject(2**100000000)


def test_create_string_object_exception():
Expand Down

0 comments on commit d9ba817

Please sign in to comment.