diff --git a/src/pypdfium2/_cli/main.py b/src/pypdfium2/_cli/main.py index 9e16be52a..6b6940c47 100644 --- a/src/pypdfium2/_cli/main.py +++ b/src/pypdfium2/_cli/main.py @@ -22,9 +22,7 @@ try: import argcomplete except ImportError: - have_argcomplete = False -else: - have_argcomplete = True + argcomplete = None Subcommands = { @@ -56,7 +54,7 @@ def parse_args(argv=sys.argv[1:]): for cmd in Subcommands.values(): cmd.attach_parser(subparsers) - if have_argcomplete: + if argcomplete is not None: argcomplete.autocomplete(parser) return parser.parse_args(argv) diff --git a/src/pypdfium2/_helpers/document.py b/src/pypdfium2/_helpers/document.py index b7cb33cbe..a86947bef 100644 --- a/src/pypdfium2/_helpers/document.py +++ b/src/pypdfium2/_helpers/document.py @@ -28,9 +28,7 @@ try: import uharfbuzz as harfbuzz except ImportError: - have_harfbuzz = False -else: - have_harfbuzz = True + harfbuzz = None logger = logging.getLogger(__name__) @@ -535,7 +533,7 @@ class HarfbuzzFont: """ Harfbuzz font data helper class. """ def __init__(self, font_path): - if not have_harfbuzz: + if harfbuzz is None: raise RuntimeError("Font helpers require uharfbuzz to be installed.") self.blob = harfbuzz.Blob.from_file_path(font_path) self.face = harfbuzz.Face(self.blob) diff --git a/src/pypdfium2/_helpers/page.py b/src/pypdfium2/_helpers/page.py index 7ad44f173..3de076037 100644 --- a/src/pypdfium2/_helpers/page.py +++ b/src/pypdfium2/_helpers/page.py @@ -23,23 +23,17 @@ try: import uharfbuzz as harfbuzz except ImportError: - have_harfbuzz = False -else: - have_harfbuzz = True + harfbuzz = None try: import PIL.Image except ImportError: - have_pil = False -else: - have_pil = True + PIL = None try: import numpy.ctypeslib except ImportError: - have_numpy = False -else: - have_numpy = True + numpy = None class PdfPage: @@ -451,7 +445,7 @@ def render_tonumpy(self, **kwargs): (numpy.ndarray, str): NumPy array, and color format. """ - if not have_numpy: + if numpy is None: raise RuntimeError("NumPy library needs to be installed for render_tonumpy().") c_array, cl_format, (width, height) = self.render_base(**kwargs) @@ -471,7 +465,7 @@ def render_topil(self, **kwargs): PIL.Image.Image: An image of the page. """ - if not have_pil: + if PIL is None: raise RuntimeError("Pillow library needs to be installed for render_topil().") c_array, cl_src, size = self.render_base(**kwargs)