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 jhewitt
Recipients jhewitt, matrixise, steven.daprano
Date 2018-10-25.20:14:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <4c5edf3e-8c01-15c0-b094-0d192345b5a0@caurinus.com>
In-reply-to <1540497511.96.0.788709270274.issue35069@psf.upfronthosting.co.za>
Content
I don't quite follow...  the 'import logging.config' statement should 
never be executed, and if it is commented out the program works fine as 
written.  It's as if the mere presence of the statement in the code 
causes 'logging' to be shadowed inside the function.

-James

On 10/25/2018 12:58 PM, Steven D'Aprano wrote:
> 
> Steven D'Aprano <steve+python@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 <report@bugs.python.org>
> <https://bugs.python.org/issue35069>
> _______________________________________
>
History
Date User Action Args
2018-10-25 20:14:48jhewittsetrecipients: + jhewitt, steven.daprano, matrixise
2018-10-25 20:14:47jhewittlinkissue35069 messages
2018-10-25 20:14:47jhewittcreate