custom-components / pyscript

Pyscript adds rich Python scripting to HASS
Apache License 2.0
874 stars 46 forks source link

Ignore failure to delete list comp variables #535

Closed akonradi closed 11 months ago

akonradi commented 11 months ago

When iterating over a generator expression gen in a list comprehension [for x in gen], the local variable x holds the value of each generated expression. When the list comprehension is done being evaluated, the local variable x needs to be deleted. This was already being done. If, however, gen is empty, x is never defined, and so deleting it causes an error. This patch adds a check to ignore that error.

Fixes #236

craigbarratt commented 11 months ago

Thanks for fixing this issues and submitting a PR. There are two pylint errors; could you fix those please?

custom_components/pyscript/eval.py:1758:16: C0103: Variable name "e" doesn't conform to snake_case naming style (invalid-name)
custom_components/pyscript/eval.py:1758:16: W0612: Unused variable 'e' (unused-variable)
akonradi commented 11 months ago

Whoops, fixed.

craigbarratt commented 11 months ago

Awesome! Thanks for the PR. Somehow I missed the original issue.