Skip to content

[Backport 8.x] Switch to Black 2025 and isort 6 #2787

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

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion elasticsearch/dsl/_sync/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@
# under the License.

import contextlib
from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, cast
from typing import (
TYPE_CHECKING,
Any,
Dict,
Iterator,
List,
Optional,
cast,
)

from typing_extensions import Self

Expand Down
68 changes: 51 additions & 17 deletions elasticsearch/dsl/response/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,19 @@
class Response(AttrDict[Any], Generic[_R]):
"""An Elasticsearch search response.

:arg took: (required)
:arg timed_out: (required)
:arg _shards: (required)
:arg took: (required) The number of milliseconds it took Elasticsearch
to run the request. This value is calculated by measuring the time
elapsed between receipt of a request on the coordinating node and
the time at which the coordinating node is ready to send the
response. It includes: * Communication time between the
coordinating node and data nodes * Time the request spends in the
search thread pool, queued for execution * Actual run time It
does not include: * Time needed to send the request to
Elasticsearch * Time needed to serialize the JSON response * Time
needed to send the response to a client
:arg timed_out: (required) If `true`, the request timed out before
completion; returned results may be partial or empty.
:arg _shards: (required) A count of shards used for the request.
:arg hits: search results
:arg aggregations: aggregation results
:arg _clusters:
Expand All @@ -64,7 +74,11 @@ class Response(AttrDict[Any], Generic[_R]):
:arg num_reduce_phases:
:arg profile:
:arg pit_id:
:arg _scroll_id:
:arg _scroll_id: The identifier for the search and its search context.
You can use this scroll ID with the scroll API to retrieve the
next batch of search results for the request. This property is
returned only if the `scroll` query parameter is specified in the
request.
:arg suggest:
:arg terminated_early:
"""
Expand Down Expand Up @@ -303,22 +317,42 @@ def __iter__(self) -> Iterator[AggregateResponseType]: # type: ignore[override]
class UpdateByQueryResponse(AttrDict[Any], Generic[_R]):
"""An Elasticsearch update by query response.

:arg batches:
:arg failures:
:arg noops:
:arg deleted:
:arg requests_per_second:
:arg retries:
:arg batches: The number of scroll responses pulled back by the update
by query.
:arg failures: Array of failures if there were any unrecoverable
errors during the process. If this is non-empty then the request
ended because of those failures. Update by query is implemented
using batches. Any failure causes the entire process to end, but
all failures in the current batch are collected into the array.
You can use the `conflicts` option to prevent reindex from ending
when version conflicts occur.
:arg noops: The number of documents that were ignored because the
script used for the update by query returned a noop value for
`ctx.op`.
:arg deleted: The number of documents that were successfully deleted.
:arg requests_per_second: The number of requests per second
effectively run during the update by query.
:arg retries: The number of retries attempted by update by query.
`bulk` is the number of bulk actions retried. `search` is the
number of search actions retried.
:arg task:
:arg timed_out:
:arg took:
:arg total:
:arg updated:
:arg version_conflicts:
:arg timed_out: If true, some requests timed out during the update by
query.
:arg took: The number of milliseconds from start to end of the whole
operation.
:arg total: The number of documents that were successfully processed.
:arg updated: The number of documents that were successfully updated.
:arg version_conflicts: The number of version conflicts that the
update by query hit.
:arg throttled:
:arg throttled_millis:
:arg throttled_millis: The number of milliseconds the request slept to
conform to `requests_per_second`.
:arg throttled_until:
:arg throttled_until_millis:
:arg throttled_until_millis: This field should always be equal to zero
in an _update_by_query response. It only has meaning when using
the task API, where it indicates the next time (in milliseconds
since epoch) a throttled request will be run again in order to
conform to `requests_per_second`.
"""

_search: "UpdateByQueryBase[_R]"
Expand Down
6 changes: 3 additions & 3 deletions elasticsearch/dsl/search_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,12 +698,12 @@ def ensure_strings(fields: "InstrumentedField") -> str: ...

@overload
def ensure_strings(
fields: List[Union[str, "InstrumentedField"]]
fields: List[Union[str, "InstrumentedField"]],
) -> List[str]: ...

@overload
def ensure_strings(
fields: Dict[str, List[Union[str, "InstrumentedField"]]]
fields: Dict[str, List[Union[str, "InstrumentedField"]]],
) -> Dict[str, List[str]]: ...

def ensure_strings(
Expand All @@ -712,7 +712,7 @@ def ensure_strings(
"InstrumentedField",
List[Union[str, "InstrumentedField"]],
Dict[str, List[Union[str, "InstrumentedField"]]],
]
],
) -> Union[str, List[str], Dict[str, List[str]]]:
if isinstance(fields, dict):
return {k: ensure_strings(v) for k, v in fields.items()}
Expand Down
8 changes: 4 additions & 4 deletions elasticsearch/dsl/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,9 @@ class FieldAndFormat(AttrDict[Any]):
A reference to a field with formatting instructions on how to return
the value

:arg field: (required) Wildcard pattern. The request returns values
:arg field: (required) A wildcard pattern. The request returns values
for field names matching this pattern.
:arg format: Format in which the values are returned.
:arg format: The format in which the values are returned.
:arg include_unmapped:
"""

Expand Down Expand Up @@ -5630,8 +5630,8 @@ class RateAggregate(AttrDict[Any]):

class Retries(AttrDict[Any]):
"""
:arg bulk: (required)
:arg search: (required)
:arg bulk: (required) The number of bulk actions retried.
:arg search: (required) The number of search actions retried.
"""

bulk: int
Expand Down
5 changes: 4 additions & 1 deletion elasticsearch/helpers/vectorstore/_sync/vectorstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
from elasticsearch import Elasticsearch
from elasticsearch._version import __versionstr__ as lib_version
from elasticsearch.helpers import BulkIndexError, bulk
from elasticsearch.helpers.vectorstore import EmbeddingService, RetrievalStrategy
from elasticsearch.helpers.vectorstore import (
EmbeddingService,
RetrievalStrategy,
)
from elasticsearch.helpers.vectorstore._utils import maximal_marginal_relevance

logger = logging.getLogger(__name__)
Expand Down
7 changes: 6 additions & 1 deletion examples/dsl/search_as_you_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
import os
from typing import TYPE_CHECKING, Optional

from elasticsearch.dsl import Document, SearchAsYouType, connections, mapped_field
from elasticsearch.dsl import (
Document,
SearchAsYouType,
connections,
mapped_field,
)
from elasticsearch.dsl.query import MultiMatch


Expand Down
8 changes: 5 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def test_otel(session):

@nox.session()
def format(session):
session.install(".", "black~=24.0", "isort", "flynt", "unasync>=0.6.0", "jinja2")
session.install(
".", "black~=25.0", "isort~=6.0", "flynt", "unasync>=0.6.0", "jinja2"
)

session.run("python", "utils/run-unasync.py")
session.run("python", "utils/run-unasync-dsl.py")
Expand All @@ -88,9 +90,9 @@ def lint(session):

session.install(
"flake8",
"black~=24.0",
"black~=25.0",
"mypy",
"isort",
"isort~=6.0",
"types-requests",
"types-python-dateutil",
"unasync>=0.6.0",
Expand Down
9 changes: 8 additions & 1 deletion test_elasticsearch/test_dsl/_sync/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
import pytest
from pytest import raises

from elasticsearch.dsl import Date, Document, Index, IndexTemplate, Text, analyzer
from elasticsearch.dsl import (
Date,
Document,
Index,
IndexTemplate,
Text,
analyzer,
)


class Post(Document):
Expand Down
10 changes: 9 additions & 1 deletion test_elasticsearch/test_dsl/_sync/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@
import pytest
from pytest import raises

from elasticsearch.dsl import Document, EmptySearch, Q, Search, query, types, wrappers
from elasticsearch.dsl import (
Document,
EmptySearch,
Q,
Search,
query,
types,
wrappers,
)
from elasticsearch.dsl.exceptions import IllegalOperation


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@
from pytest import raises

from elasticsearch import ApiError, Elasticsearch
from elasticsearch.dsl import Date, Document, Keyword, MultiSearch, Q, Search, Text
from elasticsearch.dsl import (
Date,
Document,
Keyword,
MultiSearch,
Q,
Search,
Text,
)
from elasticsearch.dsl.response import aggs

from ..test_data import FLAT_DATA
Expand Down
4 changes: 2 additions & 2 deletions test_elasticsearch/test_dsl/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_iterating_over_response_gives_you_hits(dummy_response: Dict[str, Any])


def test_hits_get_wrapped_to_contain_additional_attrs(
dummy_response: Dict[str, Any]
dummy_response: Dict[str, Any],
) -> None:
res = response.Response(Search(), dummy_response)
hits = res.hits
Expand All @@ -140,7 +140,7 @@ def test_hits_get_wrapped_to_contain_additional_attrs(


def test_hits_provide_dot_and_bracket_access_to_attrs(
dummy_response: Dict[str, Any]
dummy_response: Dict[str, Any],
) -> None:
res = response.Response(Search(), dummy_response)
h = res.hits[0]
Expand Down