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

Hi

I have some code like this

try:
    import psycopg2
    import psycopg2.extras
except ImportError:
    pass

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.

Thanks

Please sign in to leave a comment.