custom-components/pyscript

NameError with inner functions and variable shadowing

Closed this issue · 3 comments

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.

Whoa - definitely a bug. Thanks for reporting.

Wow, that was quick!

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