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] helpers.bulk action is incorrectly typed #154

Closed
pejter opened this issue Apr 12, 2022 · 6 comments · Fixed by #239
Closed

[BUG] helpers.bulk action is incorrectly typed #154

pejter opened this issue Apr 12, 2022 · 6 comments · Fixed by #239
Assignees
Labels
enhancement New feature or request

Comments

@pejter
Copy link

pejter commented Apr 12, 2022

Is your feature request related to a problem?
When using helpers.bulk in a typed environment I need to manually cast the result to either tuple[int, int] or tuple[int, list[Any]] depending on the value of stats_only argument.

What solution would you like?
You can introduce overloads to the relevant functions which return different types depending on arguments like helpers.bulk

@overload
def bulk(
    client: OpenSearch,
    actions: Iterable[Any],
    stats_only: Literal[True] = ...,
    ignore_status: Optional[Union[int, Collection[int]]] = ...,
    *args: Any,
    **kwargs: Any
) -> Tuple[int, int]: ...

@overload
def bulk(
    client: OpenSearch,
    actions: Iterable[Any],
    stats_only: Literal[False],
    ignore_status: Optional[Union[int, Collection[int]]] = ...,
    *args: Any,
    **kwargs: Any
) -> Tuple[int, List[Any]]: ...
@pejter pejter added enhancement New feature or request untriaged Need triage labels Apr 12, 2022
@wbeckler
Copy link
Contributor

Can you imagine a scenario where introducing this fix would break someone's already working code that relied on the old result typing? If so we'd need to keep track of which version we do this in, or maybe fix it in a way that couldn't break old code.

@pejter
Copy link
Author

pejter commented Aug 26, 2022

I don't think there's a way you can depend on this that breaks with the proposed change.
The overall function type stays the same, so if you passed an arbitrary bool to the function then you'd get the same resulting type.
But if you passed True or False you'd now get a more specific type instead of the generic one.

In the end adding overloads doesn't change anything when it comes to the existing code, the original function definition is still the same (just with an added @overload decorator) and it behaves exactly the same, but there is now additional information for the typing system in the form of the other 2 overloads which I've posted. If you imagine a diff for this change it would just be adding the above lines plus the @overload decorator for the actual implementation.

@wbeckler
Copy link
Contributor

This makes total sense. Feel free to submit a PR for this.

@wbeckler
Copy link
Contributor

@pejter Would you be up for submitting a PR for this?

@wbeckler wbeckler removed the untriaged Need triage label Nov 3, 2022
@harshavamsi
Copy link
Collaborator

@saimedhi can you take a look?

@saimedhi
Copy link
Collaborator

saimedhi commented Nov 7, 2022

yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment