Skip to content

Functions are not properly scoped #6

@codinghipster

Description

@codinghipster

It appears that functions (and by extension, lambdas) don't have access to things outside their scope, example:

def foobar():
    pass

foobar()
(lambda: foobar())()

Fails with:

2021-09-17 19:05:11 ERROR (SyncWorker_6) [custom_components.python_script] Error executing script: name 'foobar' is not defined
Traceback (most recent call last):
  File "/config/custom_components/python_script/__init__.py", line 81, in execute_script
    exec(code)
  File "/config/python_scripts/example.py", line 7, in <module>
    (lambda: foobar())()
  File "/config/python_scripts/example.py", line 7, in <lambda>
    (lambda: foobar())()
NameError: name 'foobar' is not defined

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions