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

Bulk action typing does not allow TypedDict #2523

Open
floxay opened this issue Apr 5, 2024 · 0 comments
Open

Bulk action typing does not allow TypedDict #2523

floxay opened this issue Apr 5, 2024 · 0 comments

Comments

@floxay
Copy link

floxay commented Apr 5, 2024

Elasticsearch version (bin/elasticsearch --version): -

elasticsearch-py version (elasticsearch.__versionstr__): 8.13.0

Description of the problem including expected versus actual behavior:
Currently bulk actions are typed with Dict;

_TYPE_BULK_ACTION = Union[bytes, str, Dict[str, Any]]
_TYPE_BULK_ACTION_HEADER = Dict[str, Any]
_TYPE_BULK_ACTION_BODY = Union[None, bytes, Dict[str, Any]]
_TYPE_BULK_ACTION_HEADER_AND_BODY = Tuple[
_TYPE_BULK_ACTION_HEADER, _TYPE_BULK_ACTION_BODY
]
this however does not allow the usage of TypedDicts.

For example, the relevant part of the signature of elasticsearch.helpers.actions.bulk currently looks like this;

def bulk(
client: Elasticsearch,
actions: Iterable[_TYPE_BULK_ACTION],
If we have a TypedDict for actions defined:

class Action(TypedDict):
	_op_type: str
	_index: str
	...

and we try to pass a list[Action] to actions then Mypy will complain:
Argument "actions" to "bulk" has incompatible type "list[Action]"; expected "Iterable[bytes | str | dict[str, Any]]"

Changing Dict to Mapping would resolve this issue.

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

No branches or pull requests

2 participants