Skip to content

Commit 4cdac46

Browse files
tests/test_typing.py: new, check that mypy finds py.typed file in pymupdf install.
1 parent 8082e12 commit 4cdac46

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

tests/test_typing.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import os
2+
import subprocess
3+
4+
import pymupdf
5+
6+
7+
def run(command, check=1):
8+
print(f'Running: {command}')
9+
subprocess.run(command, shell=1, check=check)
10+
11+
def test_py_typed():
12+
print(f'test_py_typed(): {pymupdf.__path__=}')
13+
run('pip uninstall -y mypy')
14+
run('pip install mypy')
15+
root = os.path.abspath(f'{__file__}/../..')
16+
17+
# Run mypy on this .py file; it will fail at `import pymypdf` if the
18+
# pymupdf install does not have a py.typed file.
19+
#
20+
# This doesn't actually check pymupdf's typing. It looks like
21+
# we can do that with `mypy -m pymupdf`, but as of 2026-1-18 this
22+
# gives many errors such as:
23+
#
24+
# ...site-packages/pymupdf/__init__.py:15346: error: point_like? has no attribute "y" [attr-defined]
25+
#
26+
# It's important to use `--no-incremental`, otherwise if one has
27+
# experimented with `mypy -m pymupdf`, this test will get the
28+
# same failures, via `.mypy_cache/` directories.
29+
#
30+
# We run in sub-directory to avoid spurious mypy errors
31+
# if there is a local mupdf/ directory.
32+
#
33+
run(f'cd {root}/tests && mypy --no-incremental {os.path.abspath(__file__)}')

0 commit comments

Comments
 (0)