Skip to content

Commit 1be0de9

Browse files
[Backport 8.x] Switch to Black 2025 and isort 6 (#2787)
* Switch to Black 2025 and isort 6 (#2779) * Switch to Black 2025 code style * Run format with isort 6 (cherry picked from commit 68f8012) * Run nox -s format --------- Co-authored-by: Quentin Pradet <quentin.pradet@elastic.co>
1 parent ab6b69d commit 1be0de9

File tree

11 files changed

+110
-35
lines changed

11 files changed

+110
-35
lines changed

elasticsearch/dsl/_sync/search.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@
1616
# under the License.
1717

1818
import contextlib
19-
from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, cast
19+
from typing import (
20+
TYPE_CHECKING,
21+
Any,
22+
Dict,
23+
Iterator,
24+
List,
25+
Optional,
26+
cast,
27+
)
2028

2129
from typing_extensions import Self
2230

elasticsearch/dsl/response/__init__.py

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,19 @@
5353
class Response(AttrDict[Any], Generic[_R]):
5454
"""An Elasticsearch search response.
5555
56-
:arg took: (required)
57-
:arg timed_out: (required)
58-
:arg _shards: (required)
56+
:arg took: (required) The number of milliseconds it took Elasticsearch
57+
to run the request. This value is calculated by measuring the time
58+
elapsed between receipt of a request on the coordinating node and
59+
the time at which the coordinating node is ready to send the
60+
response. It includes: * Communication time between the
61+
coordinating node and data nodes * Time the request spends in the
62+
search thread pool, queued for execution * Actual run time It
63+
does not include: * Time needed to send the request to
64+
Elasticsearch * Time needed to serialize the JSON response * Time
65+
needed to send the response to a client
66+
:arg timed_out: (required) If `true`, the request timed out before
67+
completion; returned results may be partial or empty.
68+
:arg _shards: (required) A count of shards used for the request.
5969
:arg hits: search results
6070
:arg aggregations: aggregation results
6171
:arg _clusters:
@@ -64,7 +74,11 @@ class Response(AttrDict[Any], Generic[_R]):
6474
:arg num_reduce_phases:
6575
:arg profile:
6676
:arg pit_id:
67-
:arg _scroll_id:
77+
:arg _scroll_id: The identifier for the search and its search context.
78+
You can use this scroll ID with the scroll API to retrieve the
79+
next batch of search results for the request. This property is
80+
returned only if the `scroll` query parameter is specified in the
81+
request.
6882
:arg suggest:
6983
:arg terminated_early:
7084
"""
@@ -303,22 +317,42 @@ def __iter__(self) -> Iterator[AggregateResponseType]: # type: ignore[override]
303317
class UpdateByQueryResponse(AttrDict[Any], Generic[_R]):
304318
"""An Elasticsearch update by query response.
305319
306-
:arg batches:
307-
:arg failures:
308-
:arg noops:
309-
:arg deleted:
310-
:arg requests_per_second:
311-
:arg retries:
320+
:arg batches: The number of scroll responses pulled back by the update
321+
by query.
322+
:arg failures: Array of failures if there were any unrecoverable
323+
errors during the process. If this is non-empty then the request
324+
ended because of those failures. Update by query is implemented
325+
using batches. Any failure causes the entire process to end, but
326+
all failures in the current batch are collected into the array.
327+
You can use the `conflicts` option to prevent reindex from ending
328+
when version conflicts occur.
329+
:arg noops: The number of documents that were ignored because the
330+
script used for the update by query returned a noop value for
331+
`ctx.op`.
332+
:arg deleted: The number of documents that were successfully deleted.
333+
:arg requests_per_second: The number of requests per second
334+
effectively run during the update by query.
335+
:arg retries: The number of retries attempted by update by query.
336+
`bulk` is the number of bulk actions retried. `search` is the
337+
number of search actions retried.
312338
:arg task:
313-
:arg timed_out:
314-
:arg took:
315-
:arg total:
316-
:arg updated:
317-
:arg version_conflicts:
339+
:arg timed_out: If true, some requests timed out during the update by
340+
query.
341+
:arg took: The number of milliseconds from start to end of the whole
342+
operation.
343+
:arg total: The number of documents that were successfully processed.
344+
:arg updated: The number of documents that were successfully updated.
345+
:arg version_conflicts: The number of version conflicts that the
346+
update by query hit.
318347
:arg throttled:
319-
:arg throttled_millis:
348+
:arg throttled_millis: The number of milliseconds the request slept to
349+
conform to `requests_per_second`.
320350
:arg throttled_until:
321-
:arg throttled_until_millis:
351+
:arg throttled_until_millis: This field should always be equal to zero
352+
in an _update_by_query response. It only has meaning when using
353+
the task API, where it indicates the next time (in milliseconds
354+
since epoch) a throttled request will be run again in order to
355+
conform to `requests_per_second`.
322356
"""
323357

324358
_search: "UpdateByQueryBase[_R]"

elasticsearch/dsl/search_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,12 +698,12 @@ def ensure_strings(fields: "InstrumentedField") -> str: ...
698698

699699
@overload
700700
def ensure_strings(
701-
fields: List[Union[str, "InstrumentedField"]]
701+
fields: List[Union[str, "InstrumentedField"]],
702702
) -> List[str]: ...
703703

704704
@overload
705705
def ensure_strings(
706-
fields: Dict[str, List[Union[str, "InstrumentedField"]]]
706+
fields: Dict[str, List[Union[str, "InstrumentedField"]]],
707707
) -> Dict[str, List[str]]: ...
708708

709709
def ensure_strings(
@@ -712,7 +712,7 @@ def ensure_strings(
712712
"InstrumentedField",
713713
List[Union[str, "InstrumentedField"]],
714714
Dict[str, List[Union[str, "InstrumentedField"]]],
715-
]
715+
],
716716
) -> Union[str, List[str], Dict[str, List[str]]]:
717717
if isinstance(fields, dict):
718718
return {k: ensure_strings(v) for k, v in fields.items()}

elasticsearch/dsl/types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,9 @@ class FieldAndFormat(AttrDict[Any]):
406406
A reference to a field with formatting instructions on how to return
407407
the value
408408
409-
:arg field: (required) Wildcard pattern. The request returns values
409+
:arg field: (required) A wildcard pattern. The request returns values
410410
for field names matching this pattern.
411-
:arg format: Format in which the values are returned.
411+
:arg format: The format in which the values are returned.
412412
:arg include_unmapped:
413413
"""
414414

@@ -5630,8 +5630,8 @@ class RateAggregate(AttrDict[Any]):
56305630

56315631
class Retries(AttrDict[Any]):
56325632
"""
5633-
:arg bulk: (required)
5634-
:arg search: (required)
5633+
:arg bulk: (required) The number of bulk actions retried.
5634+
:arg search: (required) The number of search actions retried.
56355635
"""
56365636

56375637
bulk: int

elasticsearch/helpers/vectorstore/_sync/vectorstore.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
from elasticsearch import Elasticsearch
2323
from elasticsearch._version import __versionstr__ as lib_version
2424
from elasticsearch.helpers import BulkIndexError, bulk
25-
from elasticsearch.helpers.vectorstore import EmbeddingService, RetrievalStrategy
25+
from elasticsearch.helpers.vectorstore import (
26+
EmbeddingService,
27+
RetrievalStrategy,
28+
)
2629
from elasticsearch.helpers.vectorstore._utils import maximal_marginal_relevance
2730

2831
logger = logging.getLogger(__name__)

examples/dsl/search_as_you_type.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@
2828
import os
2929
from typing import TYPE_CHECKING, Optional
3030

31-
from elasticsearch.dsl import Document, SearchAsYouType, connections, mapped_field
31+
from elasticsearch.dsl import (
32+
Document,
33+
SearchAsYouType,
34+
connections,
35+
mapped_field,
36+
)
3237
from elasticsearch.dsl.query import MultiMatch
3338

3439

noxfile.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ def test_otel(session):
6666

6767
@nox.session()
6868
def format(session):
69-
session.install(".", "black~=24.0", "isort", "flynt", "unasync>=0.6.0", "jinja2")
69+
session.install(
70+
".", "black~=25.0", "isort~=6.0", "flynt", "unasync>=0.6.0", "jinja2"
71+
)
7072

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

8991
session.install(
9092
"flake8",
91-
"black~=24.0",
93+
"black~=25.0",
9294
"mypy",
93-
"isort",
95+
"isort~=6.0",
9496
"types-requests",
9597
"types-python-dateutil",
9698
"unasync>=0.6.0",

test_elasticsearch/test_dsl/_sync/test_index.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@
2222
import pytest
2323
from pytest import raises
2424

25-
from elasticsearch.dsl import Date, Document, Index, IndexTemplate, Text, analyzer
25+
from elasticsearch.dsl import (
26+
Date,
27+
Document,
28+
Index,
29+
IndexTemplate,
30+
Text,
31+
analyzer,
32+
)
2633

2734

2835
class Post(Document):

test_elasticsearch/test_dsl/_sync/test_search.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@
2121
import pytest
2222
from pytest import raises
2323

24-
from elasticsearch.dsl import Document, EmptySearch, Q, Search, query, types, wrappers
24+
from elasticsearch.dsl import (
25+
Document,
26+
EmptySearch,
27+
Q,
28+
Search,
29+
query,
30+
types,
31+
wrappers,
32+
)
2533
from elasticsearch.dsl.exceptions import IllegalOperation
2634

2735

test_elasticsearch/test_dsl/test_integration/_sync/test_search.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@
2020
from pytest import raises
2121

2222
from elasticsearch import ApiError, Elasticsearch
23-
from elasticsearch.dsl import Date, Document, Keyword, MultiSearch, Q, Search, Text
23+
from elasticsearch.dsl import (
24+
Date,
25+
Document,
26+
Keyword,
27+
MultiSearch,
28+
Q,
29+
Search,
30+
Text,
31+
)
2432
from elasticsearch.dsl.response import aggs
2533

2634
from ..test_data import FLAT_DATA

test_elasticsearch/test_dsl/test_result.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def test_iterating_over_response_gives_you_hits(dummy_response: Dict[str, Any])
130130

131131

132132
def test_hits_get_wrapped_to_contain_additional_attrs(
133-
dummy_response: Dict[str, Any]
133+
dummy_response: Dict[str, Any],
134134
) -> None:
135135
res = response.Response(Search(), dummy_response)
136136
hits = res.hits
@@ -140,7 +140,7 @@ def test_hits_get_wrapped_to_contain_additional_attrs(
140140

141141

142142
def test_hits_provide_dot_and_bracket_access_to_attrs(
143-
dummy_response: Dict[str, Any]
143+
dummy_response: Dict[str, Any],
144144
) -> None:
145145
res = response.Response(Search(), dummy_response)
146146
h = res.hits[0]

0 commit comments

Comments
 (0)