Open tjingsheng opened 6 months ago
Hi, thanks for reporting this. I've been able to reproduce it. Glad to let you know that I've come up with a fix and this will be made available in the subsequent release!
I'll update this thread again once the fix has been deployed 😃
Description
Unexpected behavior in python buddy when handling code that involve empty iterators. Specifically, involving simple operations like empty list comprehensions as well as a for loop iterating over an empty list, cause errors when they should not.
Link
https://pythonbuddy.dev/editor/?code=IyBDb21tZW50IG91dCBhbGwgb3RoZXIgU2VnbWVudHMgZHVyaW5nIHRlc3RpbmcuCgojIFN0YXJ0IG9mIFNlZ21lbnQgMQpmb3IgaXRlbSBpbiBbXToKICAgIHByaW50KCJUaGlzIHNob3VsZCBub3QgcHJpbnQuIikKcHJpbnQoImhlbGxvIHdvcmxkISIpICMgU2VnbWVudCAxIHdvcmtzIHdoZW4geW91IGNvbW1lbnQgb3V0IHRoaXMgbGluZS4KIyBFbmQgb2YgU2VnbWVudCAxCgojIFN0YXJ0IG9mIFNlZ21lbnQgMgpbeCBmb3IgeCBpbiBbXV0KIyBFbmQgb2YgU2VnbWVudCAyCgojIFN0YXJ0IG9mIFNlZ21lbnQgMwp7eCBmb3IgeCBpbiBbXX0KIyBFbmQgb2YgU2VnbWVudCAzCgojIFN0YXJ0IG9mIFNlZ21lbnQgNAooeCBmb3IgeCBpbiBbXSkKIyBFbmQgb2YgU2VnbWVudCA0Cgo=&filename=empty_iterator.py
Steps to Reproduce
The following code segments individually cause errors when ran in python buddy.
Segment 1: For Loop with an Empty List
Expected Behavior: No output from the loop and "hello world!" printed to the console.
Actual Behavior: Causes an error.
Segment 2: List Comprehension with an Empty Iterator
Expected Behavior: Should produce an empty list
[]
without errors.Actual Behavior: Causes an error.
Segment 3: Set Comprehension with an Empty Iterator
Expected Behavior: Should produce an empty set
{}
without errors.Actual Behavior: Causes an error.
Segment 4: Generator Object with an Empty Iterator
Expected Behavior: Should produce an empty generator without errors.
Actual Behavior: Causes an error. Note: Could be related to #4
Expected Behavior
All segments should compile and run without errors, given that they are valid Python syntax and handle empty iterators according to Python's standard behavior.
Actual Behavior
Each code segment causes an error during compilation or execution, indicating a potential issue in how empty iterators are handled by the compiler.