-
Notifications
You must be signed in to change notification settings - Fork 55
Functions defined inside if blocks don't do variable lookup correctly #263
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
Comments
This is a side effect of the way function definitions work in pyscript. Under |
Nope:
|
I have tested this myself (and every variation I can think of). It is indeed broken. Hopefully @craigbarratt can fix it. |
Yikes. It doesn't correctly detect inner functions inside nested statements, which then means the correct variable scoping isn't applied. I pushed a fix f4f32f4. A workaround for the existing code is to define a dummy inner function at the top-level, eg: value = 4
def make_func(value):
if 1:
def real_inner():
log.info(f"value = {value}")
return real_inner
def dummy_inner():
pass |
@LeszekSwirski Has your problem been fixed? Could you please update the ticket or close it? Thank you |
Honestly, I still just have the workaround in my own config, but from the looks of it it's fixed. |
If I define an inner function inside an
if
block, it fails to look up values that it closes over, doing e.g. a global lookup instead:Interestingly, however, if there is an inner function defined outside the
if
block, the one inside theif
block works as it should.The text was updated successfully, but these errors were encountered: