Pycharm is underlining the final reference to m_db_cnxn and warning me that I might be referencing the local variable before assignment because it is unaware that my error_exit function is exiting the program if an exception occurs.

This code is from my main module and the object is in another called db.

Is there a way to get around this as I assume that every reference to my connection object will have the same warning.

I would just ignore the warning, but you should be able to get rid of it by assigining the object to None before the try/except block or within the except block, thus no longer referencing a local variable before assignment