Checking module name inside 'except ImportError'
try: import MySQLdb # some action except ImportError as err: # fallback code PyCharm gives a code inspection warning on that: 'MySQLdb' in try block with 'except ImportError' should also be defined in except block This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items. Ok, I thought the warning is reasonable, because the fallback code assumes that 'MySQLdb' is not installed, while it could be some different error that