Skip to content

NameError with inner functions and variable shadowing #683

Closed

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.

Activity

  1. craigbarratt commented on Jan 17, 2025

    @craigbarratt
    Member

    Whoa - definitely a bug. Thanks for reporting.

  2. rtimush commented on Jan 17, 2025

    @rtimush
    Author

    Wow, that was quick!

  3. added a commit that references this issue on Jan 17, 2025
    9b8526f
  4. craigbarratt commented on Jan 18, 2025

    @craigbarratt
    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

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