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
Describe the bug
Flattening a list of strings result in a ValueError: cannot flatten list because it contains recursive elements.
This is because strings are Sequences, so the algorithm will try to flatten them further, but they never end up being a non-Sequence (single-char strings are still strings) so it loops forever.
To Reproduce
Steps to reproduce the behavior:
frommagic_listimportLl=L["hello", "world"]
print(l.flatten()) # ValueError: cannot flatten list because it contains recursive elements
Expected behavior
The expected behavior is debatable. It should either give the list untouched, or flatten it to a list of characters.
Configuration:
Python version: all supported
Magic List version: all since flatten() was introduced
The fix will be a breaking change. flatten will only decrement the list dimension by one, instead of always bringing it to 1.
It will also allow to properly type the method (without using nefarious Anys): indeed, it is a known issue in languages that are not dependently-typed that it is impossible to properly type a flatten function as it is behaving before the fix.
Describe the bug
Flattening a list of strings result in a
ValueError: cannot flatten list because it contains recursive elements
.This is because strings are
Sequence
s, so the algorithm will try to flatten them further, but they never end up being a non-Sequence
(single-char strings are still strings) so it loops forever.To Reproduce
Steps to reproduce the behavior:
Expected behavior
The expected behavior is debatable. It should either give the list untouched, or flatten it to a list of characters.
Configuration:
flatten()
was introducedAdditional context
Found after reading https://discuss.python.org/t/collections-abc-nonstringsequence/53274
The text was updated successfully, but these errors were encountered: