This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients jhewitt, matrixise, steven.daprano
Date 2018-10-25.19:58:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1540497511.96.0.788709270274.issue35069@psf.upfronthosting.co.za>
In-reply-to
Content
This is expected behaviour: import is a form of assignment. 

"import logging", like "logging = 1", tells the compiler to treat logging as a local variable (unless you declare logging as global). As the exception says, you are trying to access the logging local variable before it has been assigned to.

You can (and should!) give a SHORT and SIMPLE demonstration, without any excess and irrelevant code:

py> def demo():
...     if False:
...             import logging
...     logging
...
py> demo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in demo
UnboundLocalError: local variable 'logging' referenced before assignment

So this is expected behaviour.
History
Date User Action Args
2018-10-25 19:58:31steven.dapranosetrecipients: + steven.daprano, matrixise, jhewitt
2018-10-25 19:58:31steven.dapranosetmessageid: <1540497511.96.0.788709270274.issue35069@psf.upfronthosting.co.za>
2018-10-25 19:58:31steven.dapranolinkissue35069 messages
2018-10-25 19:58:31steven.dapranocreate