elasticsearch-py
elasticsearch-py copied to clipboard
Bulk action typing does not allow `TypedDict`
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;
https://github.com/elastic/elasticsearch-py/blob/794341dd05305885c70597970c0a2dea2585924e/elasticsearch/helpers/actions.py#L45-L50 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;
https://github.com/elastic/elasticsearch-py/blob/794341dd05305885c70597970c0a2dea2585924e/elasticsearch/helpers/actions.py#L478-L480 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.