Skip to content
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

NameError with inner functions and variable shadowing #683

Closed
rtimush opened this issue Jan 16, 2025 · 3 comments
Closed

NameError with inner functions and variable shadowing #683

rtimush opened this issue Jan 16, 2025 · 3 comments

Comments

@rtimush
Copy link

rtimush commented Jan 16, 2025

The following code snippet

def foo():
    def bar():
        result = []
        result.append("bar")
        return result

    result = bar()
    print(result)

@webhook_trigger("test")
def test():
    foo()

fails with

Exception in <file.test.test> line 3:            
         def bar():
         ^
 NameError: name 'result' is not defined

when triggered.

If I rename the outer variable (in foo()) everything works.
If i remove the append call everything works too.
The same code snippet executed without pyscript works fine.

@craigbarratt
Copy link
Member

Whoa - definitely a bug. Thanks for reporting.

@rtimush
Copy link
Author

rtimush commented Jan 17, 2025

Wow, that was quick!

@craigbarratt
Copy link
Member

Thanks for reducing it to a simple example and providing a succinct bug report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants