Skip to content
Permalink
Browse files

RF: use isinstance instead of type().__name__ comparison

ModuleNotFoundError is a subclass of ImportError:
  https://docs.python.org/3/library/exceptions.html#exception-hierarchy
so we can safely check via isinstance.  Moreover, it seems that
whenever exception is raised without explicit instantiation
(raise ImportError), we do catch an instance, so should work fine
  • Loading branch information...
yarikoptic committed Mar 12, 2019
1 parent b053eeb commit b61da129882800fc93e4081a7e24d68eff14d871
Showing with 2 additions and 2 deletions.
  1. +2 −2 duecredit/stub.py
@@ -24,7 +24,7 @@
License: BSD-2
"""

__version__ = '0.0.7'
__version__ = '0.0.8'


class InactiveDueCreditCollector(object):
@@ -57,7 +57,7 @@ def _donothing_func(*args, **kwargs):
raise RuntimeError(
"Imported due lacks .cite. DueCredit is now disabled")
except Exception as e:
if type(e).__name__ not in ('ImportError', 'ModuleNotFoundError'):
if not isinstance(e, ImportError):
import logging
logging.getLogger("duecredit").error(
"Failed to import duecredit due to %s" % str(e))

0 comments on commit b61da12

Please sign in to comment.
You can’t perform that action at this time.