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

chore: rename get_iterable #24994

Merged
merged 7 commits into from
Aug 18, 2023
Merged

chore: rename get_iterable #24994

merged 7 commits into from
Aug 18, 2023

Conversation

betodealmeida
Copy link
Member

@betodealmeida betodealmeida commented Aug 15, 2023

SUMMARY

get_iterable has a confusing name, I changed it to something more clear.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@betodealmeida betodealmeida changed the title chore; rename get_iterable chore: rename get_iterable Aug 15, 2023
T = TypeVar("T")


def get_as_list(x: T | list[T]) -> list[T]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just as_list?

Copy link
Member

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.

Copy link
Member Author

@betodealmeida betodealmeida Aug 16, 2023

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)]

Copy link
Member Author

@betodealmeida betodealmeida Aug 16, 2023

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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

superset/daos/chart.py Outdated Show resolved Hide resolved
@betodealmeida betodealmeida merged commit bbf0aae into master Aug 18, 2023
54 checks passed
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 3.1.0 labels Mar 8, 2024
@mistercrunch mistercrunch deleted the rename_get_iterable branch March 26, 2024 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/M 🚢 3.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants