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

bug: flattening a list of strings result in a ValueError (recursive elements) #65

Open
qexat opened this issue May 18, 2024 · 1 comment
Labels
help wanted Extra attention is needed kind: bug Something isn't working
Milestone

Comments

@qexat
Copy link
Owner

qexat commented May 18, 2024

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:

from magic_list import L

l = 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

Additional context
Found after reading https://discuss.python.org/t/collections-abc-nonstringsequence/53274

@qexat qexat added kind: bug Something isn't working help wanted Extra attention is needed labels May 18, 2024
@qexat qexat added this to the v2.5.x milestone May 18, 2024
@qexat
Copy link
Owner Author

qexat commented Jul 7, 2024

Warning

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.

More information: https://github.com/users/qexat/projects/2?pane=issue&itemId=70052105

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed kind: bug Something isn't working
Projects
Status: No status
Development

No branches or pull requests

1 participant