You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import elasticsearch
HOSTS = ['http://localhost:9200', 'http://localhost:10200'] # this will be inferred as list[str]
client = elasticsearch.Elasticsearch(hosts=HOSTS)
Mypy output
test.py:5: error: Argument "hosts" to "Elasticsearch" has incompatible type "list[str]"; expected "str | list[str | Mapping[str, str | int] | NodeConfig] | None" [arg-type]
test.py:5: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
test.py:5: note: Consider using "Sequence" instead, which is covariant
The text was updated successfully, but these errors were encountered:
Elasticsearch version (
bin/elasticsearch --version
): 8.9.0 (but it's not relevant to this bug)elasticsearch-py
version (elasticsearch.__versionstr__
): 8.10.0Description of the problem including expected versus actual behavior:
Currently
_TYPE_HOSTS
has type annotation defined asThe problem is that
List
is invariant and thusList[str]
is not valid subtype forList[Union[str, Mapping[str, Union[str, int]], NodeConfig]]]
See common mypy issue python/mypy#3351
The solution is to replace
List
withSequence
.Steps to reproduce:
Minimal example
Mypy output
The text was updated successfully, but these errors were encountered: