New submission from Michael Hipp <mich...@redmule.com>:

A local *unexecuted* import appears to be changing the namespace. Attached 
files are ready to run.

# over.py
SOMETHING = "overridden"

# main.py
OVERRIDE = False
SOMETHING = "original"

def main():
    #global SOMETHING  # uncomment and it works
    if OVERRIDE:
        from over import SOMETHING  # comment out and it works
        pass
    print SOMETHING  # UnboundLocalError: local variable 'SOMETHING' referenced 
before assignment

The SOMETHING variable has a value from the module global namespace, but it 
gets lost due to an import that is never executed.

I would think an unexecuted statement shouldn't have any effect on anything.

The second file will have to be submitted in a follow-on, it appears

----------
components: None
files: main.py
messages: 151635
nosy: hippmr
priority: normal
severity: normal
status: open
title: Unexecuted import changes namespace
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file24278/main.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13827>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to