[issue45294] Conditional import fails and produce UnboundLocalError, if a variable machting import name is used before

arts stars report at bugs.python.org
Sun Sep 26 11:25:13 EDT 2021


New submission from arts stars <stars-of-stras at mediapromo.be>:

Hello,

I have this situation:
----------------
def test():
    
    if True :
        print("Exception"+DiaObjectFactoryHelper)
    else:
        from . import DiaObjectFactoryHelper
        pass
        
test()
---------------
it generates instead of (like the the line 'from . import' is commented) : 
"NameError: name 'DiaObjectFactoryHelper' is not defined"
this:
UnboundLocalError: local variable 'DiaObjectFactoryHelper' referenced before assignment


PS: The github authentificatiion did not work, did not manage to grab email even if set public

----------
messages: 402663
nosy: stars-of-stras
priority: normal
severity: normal
status: open
title: Conditional import fails and produce UnboundLocalError, if a variable machting import name is used before
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45294>
_______________________________________


More information about the Python-bugs-list mailing list