From 4f3ccf213d813bb57775b2643b8bae5e08cbbbd0 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Tue, 3 Jan 2023 15:21:15 -0500 Subject: refactor: a better way to have maybe-importable third-party modules --- coverage/misc.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'coverage/misc.py') diff --git a/coverage/misc.py b/coverage/misc.py index 1e4b4e74..bd1767ca 100644 --- a/coverage/misc.py +++ b/coverage/misc.py @@ -83,14 +83,16 @@ def import_third_party(modname): modname (str): the name of the module to import. Returns: - The imported module, or None if the module couldn't be imported. + The imported module, and a boolean indicating if the module could be imported. + + If the boolean is False, the module returned is not the one you want: don't use it. """ with sys_modules_saved(): try: - return importlib.import_module(modname) + return importlib.import_module(modname), True except ImportError: - return None + return sys, False def nice_pair(pair): -- cgit v1.2.1