Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore failure to delete list comp variables #535

Merged
merged 1 commit into from
Oct 18, 2023

Conversation

akonradi
Copy link
Contributor

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
Copy link
Member

craigbarratt commented Oct 18, 2023

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)

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.
@akonradi
Copy link
Contributor Author

Whoops, fixed.

@craigbarratt craigbarratt merged commit ba15d6c into custom-components:master Oct 18, 2023
6 checks passed
@craigbarratt
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

List comprehension failing with an empty list
2 participants