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

2021-09-27 Thread Steven D'Aprano
Steven D'Aprano added the comment: I'm glad that you fixed the bug in your code, but this is not a bug in Python. It isn't "a parsing issue", the code is parsed fine. What you did was no different from: def func(): print(x) x = 1 except that the binding operation was an

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

2021-09-27 Thread arts stars
arts stars added the comment: It is not for debuging my code. your answer is really middleclass sorry to say that. you admit its a due the undefined name of var DiaObjectFactoryHelper that is exactly I wanted to point out. I solved my issue not having answer like in the FAQ like you simply

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

2021-09-26 Thread Steven D'Aprano
Steven D'Aprano added the comment: In the future, please remember that this is not a help desk for getting help with your code, it is for reporting bugs. There are many forums that are happy to help you understand why your code is not working as you expect (if you are a beginner to Python, t

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

2021-09-26 Thread Steven D'Aprano
Steven D'Aprano added the comment: This is not a bug, you are trying to print the value of the local variable DiaObjectFactoryHelper before you have defined the variable. UnboundLocalError is a subclass of NameError that is used when the undefined name is a local variable instead of a global

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

2021-09-26 Thread arts stars
New submission from arts stars : Hello, I have this situation: def test(): if True : print("Exception"+DiaObjectFactoryHelper) else: from . import DiaObjectFactoryHelper pass test() --- it generates instead of (like the