New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditional import fails and produce UnboundLocalError, if a variable machting import name is used before #89457
Comments
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) : PS: The github authentificatiion did not work, did not manage to grab email even if set public |
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. |
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, the answer is *almost never* "a bug in Python"). You can find help at Reddit's r/learnpython, or at the forums and mailing lists here: |
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 I solved my issue not having answer like in the FAQ like you simply repeated here. This is a parsing issue error I revealed here. The if... should pe PRIORITARIZED before checking what it is said in the FAQ. |
I'm glad that you fixed the bug in your code, but this is not a bug in def func():
print(x)
x = 1 except that the binding operation was an import, not an assignment. You def func():
print(math)
import math That's the way the language is defined. Imports and assignments are both |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: