Skip to content

NameError with inner functions and variable shadowing #683

@rtimush

Description

@rtimush

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions