From a022b71810a6bcb7e772d6ddc8d83d5c01285475 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Wed, 26 Aug 2026 12:22:03 +0100 Subject: [PATCH 1/2] src/fitz___init__.py: change fitz deprecation warning to use warnings.warn(). --- src/fitz___init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/fitz___init__.py b/src/fitz___init__.py index 95fc9ce4c..d8bc645fb 100644 --- a/src/fitz___init__.py +++ b/src/fitz___init__.py @@ -1,3 +1,5 @@ +import warnings + # pylint: disable=wildcard-import,unused-import,unused-wildcard-import,no-name-in-module from pymupdf import * from pymupdf import _as_fz_document @@ -12,4 +14,7 @@ from pymupdf import _globals from pymupdf import _g_out_message -message_warning('The `fitz` API is deprecated and will be removed in future. Use `import pymupdf` instead.') +warnings.warn( + 'The `fitz` API is deprecated and will be removed in future. Use `import pymupdf` instead.', + FutureWarning, + ) From 1b82ecdc3c1bd2b5c28e858c86e7ff1878b38e37 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Wed, 26 Aug 2026 12:22:30 +0100 Subject: [PATCH 2/2] tests/test_general.py:test_5100(): new, test fitz deprecation warnings. --- tests/test_general.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/test_general.py b/tests/test_general.py index 9dc2f25d6..3cc4ed29c 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -2281,3 +2281,37 @@ def test_5054(): assert text2 != text1 else: assert text2 == text1 + +def test_5100(): + print() + + def run(code): + code = textwrap.dedent(code) + print(f'code is:\n{textwrap.indent(code, " ")}') + path = os.path.normpath(f'{__file__}/../../tests/_test_5100.py') + with open(path, 'w') as f: + f.write(code) + cp = subprocess.run(f'{sys.executable} {path}', shell=1, check=1, capture_output=1) + print(f'{cp.stdout=}') + print(f'{cp.stderr=}') + return cp + + cp = run(''' + import pymupdf + ''') + assert cp.stdout == b'' + assert cp.stderr == b'' + + cp = run(''' + import fitz + ''') + assert cp.stdout == b'' + assert b'FutureWarning: The `fitz` API is deprecated and will be removed in future. Use `import pymupdf` instead' in cp.stderr + + cp = run(''' + import warnings + warnings.filterwarnings('ignore', category=FutureWarning, module='fitz') + import fitz + ''') + assert cp.stdout == b'' + assert cp.stderr == b''