Explain: in try block with 'except ImportError' should also be defined in except block


I have some code like this

    import psycopg2
    import psycopg2.extras
except ImportError:

The 2 import lines trigger Pycharm to issue the warning below; could someone explain what this means please? And ideally a way of avoiding the warning

'psycopg2' 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.


Please sign in to leave a comment.