You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following very simple list comprehension works fine in the interactive Python interpreter, but fails if used in PyScript:
[x for x in []]
I would expect it to return an empty list ([]), as it does in the interactive interpreter:
>>> [x for x in []]
[]
but PyScript gives an error:
[x for x in []]
^
KeyError: 'x'
It's not a very interesting example, but I've had situations where an incoming iterable may be empty and it's easier to just execute the list comprehension without having to add an if xxx to the end to filter empty lists. I've worked around it with a for loop, but I didn't see a limitation explicitly called out in the docs and wanted to file an issue for it.
Weirdly, I have seen this construct work as expected sometimes, but I can get to to reliably fail if I write an app like this:
@time_trigger('startup')
def startup():
[x for x in []]
The text was updated successfully, but these errors were encountered:
The following very simple list comprehension works fine in the interactive Python interpreter, but fails if used in PyScript:
[x for x in []]
I would expect it to return an empty list (
[]
), as it does in the interactive interpreter:but PyScript gives an error:
It's not a very interesting example, but I've had situations where an incoming iterable may be empty and it's easier to just execute the list comprehension without having to add an
if xxx
to the end to filter empty lists. I've worked around it with afor
loop, but I didn't see a limitation explicitly called out in the docs and wanted to file an issue for it.Weirdly, I have seen this construct work as expected sometimes, but I can get to to reliably fail if I write an app like this:
The text was updated successfully, but these errors were encountered: