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
2 comments
Comment actions Permalink

is there anyone know what's wrong with it, i encounter the same issue,

ImportError: notifications are not supported, can't import necessary library

0
Comment actions Permalink

Please share a screenshot showing the issue and your code for a better understanding.

The code provided in the original issue description doesn't trigger any warnings in my environment.

0

Please sign in to leave a comment.