Skip to content

Commit

Permalink
FIXES: pymupdf#2961
Browse files Browse the repository at this point in the history
  • Loading branch information
bwagner committed Jan 2, 2024
1 parent b8879fe commit 3b67884
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src_classic/fitz_old.i
Original file line number Diff line number Diff line change
Expand Up @@ -4800,6 +4800,8 @@ if basestate:


def __getitem__(self, i: int =0)->"Page":
if (t:= type(i)) != int:
raise TypeError(f"Wrong type used for index. Expected 'int' but got '{t.__name__}'")
if i not in self:
raise IndexError("page not in document")
return self.load_page(i)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_pixmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import platform
import sys
import tempfile
import pytest

scriptdir = os.path.abspath(os.path.dirname(__file__))
epub = os.path.join(scriptdir, "resources", "Bezier.epub")
Expand Down Expand Up @@ -132,3 +133,10 @@ def test_2369():
img_bytes = img["image"]
fitz.Pixmap(img_bytes)

def test_page_idx_int():
pdf = os.path.join(scriptdir, "resources", "mupdf_explored.pdf")
doc = fitz.open(pdf)
with pytest.raises(TypeError) as err:
doc["3"]
assert "Wrong type used for index. Expected 'int' but got 'str'" in str(err.value)

0 comments on commit 3b67884

Please sign in to comment.