Skip to content

Commit

Permalink
Changed ModuleNotFoundError for ImportError superclass in except blocks
Browse files Browse the repository at this point in the history
ModuleNotFoundError is only risen in Python 3.6 and above.
  • Loading branch information
FosanzDev committed Jun 19, 2024
1 parent 25f732e commit 8f07525
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tlslite/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@
from .integration.tlsasynciodispatchermixin \
import TLSAsyncioDispatcherMixIn

except ModuleNotFoundError:
except ImportError:
# ModuleNotFoundError is a subclass of ImportError. Python 2 does not
# raise ModuleNotFoundError, so we need to catch ImportError instead.
# ModuleNotFoundError is returned in Python 3.6 and above.

# NOTE: asyncio is not available in base python 2, so this try-except
# block is necessary to avoid breaking the import of the
# rest of the module.
pass

try:
from .integration.tlsasyncdispatchermixin import TLSAsyncDispatcherMixIn
except ModuleNotFoundError:
except ImportError:
# NOTE: Left this try-except block as is, due to the possibility to use
# both asyncore and asyncio in the same project no matter the python
# version (if the asyncore module is available).
Expand Down

0 comments on commit 8f07525

Please sign in to comment.