Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:
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. ---------- nosy: +steven.daprano resolution: -> not a bug stage: -> resolved status: open -> closed _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35069> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com