-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
chore: rename get_iterable
#24994
chore: rename get_iterable
#24994
Conversation
superset/utils/core.py
Outdated
T = TypeVar("T") | ||
|
||
|
||
def get_as_list(x: T | list[T]) -> list[T]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just as_list
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think either as_iterable
or as_list
is likely best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@john-bodley as_iterable
is super confusing, because there are many things that are already iterable but will still be modified by this function, eg:
>>> from typing import Any
>>> def is_iterable(foo: Any) -> bool:
... try:
... iter(foo)
... except Exception:
... return False
... return True
...
>>>
>>> a = (1,2,3)
>>> is_iterable(a)
True
>>> as_iterable(a)
[(1, 2, 3)]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And to be clear, I think this function could be called as_iterable
, but then it should be improved to not check if the passed object is a list, but instead use an improved version of the is_iterable
function above, something like this:
def is_iterable(foo: Any) -> bool:
if isinstance(foo, str):
return False
try:
iter(foo)
except Exception:
return False
return True
But that might introduce bugs. In this PR I just want to fix the erroneous name.
@@ -1578,12 +1578,15 @@ def split( | |||
yield string[i:] | |||
|
|||
|
|||
def get_iterable(x: Any) -> list[Any]: | |||
T = TypeVar("T") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
SUMMARY
get_iterable
has a confusing name, I changed it to something more clear.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION