Skip to content

Commit d045a99

Browse files
replace JSONType with Any (#1856)
1 parent 2c2d0f3 commit d045a99

17 files changed

+93
-101
lines changed

elasticsearch_dsl/_async/search.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from ..async_connections import get_connection
2626
from ..response import Response
2727
from ..search_base import MultiSearchBase, SearchBase
28-
from ..utils import _R, AsyncUsingType, AttrDict, JSONType
28+
from ..utils import _R, AsyncUsingType, AttrDict
2929

3030

3131
class AsyncSearch(SearchBase[_R]):
@@ -108,9 +108,9 @@ async def scan(self) -> AsyncIterator[_R]:
108108
async for hit in async_scan(
109109
es, query=self.to_dict(), index=self._index, **self._params
110110
):
111-
yield self._get_result(cast(AttrDict[JSONType], hit))
111+
yield self._get_result(cast(AttrDict[Any], hit))
112112

113-
async def delete(self) -> AttrDict[JSONType]:
113+
async def delete(self) -> AttrDict[Any]:
114114
"""
115115
delete() executes the query by delegating to delete_by_query()
116116
"""
@@ -120,7 +120,7 @@ async def delete(self) -> AttrDict[JSONType]:
120120

121121
return AttrDict(
122122
cast(
123-
Dict[str, JSONType],
123+
Dict[str, Any],
124124
await es.delete_by_query(
125125
index=self._index, body=self.to_dict(), **self._params
126126
),
@@ -214,5 +214,5 @@ async def scan(self) -> AsyncIterator[_R]:
214214
return
215215
yield # a bit strange, but this forces an empty generator function
216216

217-
async def delete(self) -> AttrDict[JSONType]:
218-
return AttrDict[JSONType]({})
217+
async def delete(self) -> AttrDict[Any]:
218+
return AttrDict[Any]({})

elasticsearch_dsl/_async/update_by_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def execute(self) -> "UpdateByQueryResponse[_R]":
4040
self,
4141
(
4242
await es.update_by_query(
43-
index=self._index, **self.to_dict(), **self._params # type: ignore
43+
index=self._index, **self.to_dict(), **self._params
4444
)
4545
).body,
4646
)

elasticsearch_dsl/_sync/search.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from ..connections import get_connection
2626
from ..response import Response
2727
from ..search_base import MultiSearchBase, SearchBase
28-
from ..utils import _R, AttrDict, JSONType, UsingType
28+
from ..utils import _R, AttrDict, UsingType
2929

3030

3131
class Search(SearchBase[_R]):
@@ -104,9 +104,9 @@ def scan(self) -> Iterator[_R]:
104104
es = get_connection(self._using)
105105

106106
for hit in scan(es, query=self.to_dict(), index=self._index, **self._params):
107-
yield self._get_result(cast(AttrDict[JSONType], hit))
107+
yield self._get_result(cast(AttrDict[Any], hit))
108108

109-
def delete(self) -> AttrDict[JSONType]:
109+
def delete(self) -> AttrDict[Any]:
110110
"""
111111
delete() executes the query by delegating to delete_by_query()
112112
"""
@@ -116,7 +116,7 @@ def delete(self) -> AttrDict[JSONType]:
116116

117117
return AttrDict(
118118
cast(
119-
Dict[str, JSONType],
119+
Dict[str, Any],
120120
es.delete_by_query(
121121
index=self._index, body=self.to_dict(), **self._params
122122
),
@@ -208,5 +208,5 @@ def scan(self) -> Iterator[_R]:
208208
return
209209
yield # a bit strange, but this forces an empty generator function
210210

211-
def delete(self) -> AttrDict[JSONType]:
212-
return AttrDict[JSONType]({})
211+
def delete(self) -> AttrDict[Any]:
212+
return AttrDict[Any]({})

elasticsearch_dsl/_sync/update_by_query.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ def execute(self) -> "UpdateByQueryResponse[_R]":
3939
self._response = self._response_class(
4040
self,
4141
(
42-
es.update_by_query(
43-
index=self._index, **self.to_dict(), **self._params # type: ignore
44-
)
42+
es.update_by_query(index=self._index, **self.to_dict(), **self._params)
4543
).body,
4644
)
4745
return self._response

elasticsearch_dsl/aggs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
)
3232

3333
from .response.aggs import AggResponse, BucketData, FieldBucketData, TopHitsData
34-
from .utils import _R, AttrDict, DslBase, JSONType
34+
from .utils import _R, AttrDict, DslBase
3535

3636
if TYPE_CHECKING:
3737
from .query import Query
@@ -96,10 +96,10 @@ class Agg(DslBase, Generic[_R]):
9696
def __contains__(self, key: str) -> bool:
9797
return False
9898

99-
def to_dict(self) -> Dict[str, JSONType]:
99+
def to_dict(self) -> Dict[str, Any]:
100100
d = super().to_dict()
101101
if isinstance(d[self.name], dict):
102-
n = cast(Dict[str, JSONType], d[self.name])
102+
n = cast(Dict[str, Any], d[self.name])
103103
if "meta" in n:
104104
d["meta"] = n.pop("meta")
105105
return d
@@ -170,7 +170,7 @@ def __init__(self, **params: Any):
170170
# remember self for chaining
171171
self._base = self
172172

173-
def to_dict(self) -> Dict[str, JSONType]:
173+
def to_dict(self) -> Dict[str, Any]:
174174
d = super(AggBase, self).to_dict()
175175
if isinstance(d[self.name], dict):
176176
n = cast(AttrDict[Any], d[self.name])
@@ -191,7 +191,7 @@ def __init__(self, filter: Optional[Union[str, "Query"]] = None, **params: Any):
191191
params["filter"] = filter
192192
super().__init__(**params)
193193

194-
def to_dict(self) -> Dict[str, JSONType]:
194+
def to_dict(self) -> Dict[str, Any]:
195195
d = super().to_dict()
196196
if isinstance(d[self.name], dict):
197197
n = cast(AttrDict[Any], d[self.name])

elasticsearch_dsl/analysis.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from typing import Any, ClassVar, Dict, List, Optional, Union, cast
1919

2020
from . import async_connections, connections
21-
from .utils import AsyncUsingType, AttrDict, DslBase, JSONType, UsingType, merge
21+
from .utils import AsyncUsingType, AttrDict, DslBase, UsingType, merge
2222

2323
__all__ = ["tokenizer", "analyzer", "char_filter", "token_filter", "normalizer"]
2424

@@ -52,7 +52,7 @@ def __init__(self, filter_name: str, builtin_type: str = "custom", **kwargs: Any
5252
self._name = filter_name
5353
super().__init__(**kwargs)
5454

55-
def to_dict(self) -> Dict[str, JSONType]:
55+
def to_dict(self) -> Dict[str, Any]:
5656
# only name to present in lists
5757
return self._name # type: ignore
5858

@@ -109,7 +109,7 @@ def __init__(self, name: str):
109109
self._name = name
110110
super().__init__()
111111

112-
def to_dict(self) -> Dict[str, JSONType]:
112+
def to_dict(self) -> Dict[str, Any]:
113113
# only name to present in lists
114114
return self._name # type: ignore
115115

elasticsearch_dsl/document_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from .exceptions import ValidationException
3737
from .field import Binary, Boolean, Date, Field, Float, Integer, Nested, Object, Text
3838
from .mapping import Mapping
39-
from .utils import DOC_META_FIELDS, JSONType, ObjectBase
39+
from .utils import DOC_META_FIELDS, ObjectBase
4040

4141
if TYPE_CHECKING:
4242
from elastic_transport import ObjectApiResponse
@@ -376,7 +376,7 @@ def __repr__(self) -> str:
376376
),
377377
)
378378

379-
def to_dict(self, include_meta: bool = False, skip_empty: bool = True) -> Dict[str, JSONType]: # type: ignore[override]
379+
def to_dict(self, include_meta: bool = False, skip_empty: bool = True) -> Dict[str, Any]: # type: ignore[override]
380380
"""
381381
Serialize the instance into a dictionary so that it can be saved in elasticsearch.
382382

elasticsearch_dsl/faceted_search_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from .aggs import A, Agg
2424
from .query import MatchAll, Nested, Query, Range, Terms
2525
from .response import Response
26-
from .utils import _R, AttrDict, JSONType
26+
from .utils import _R, AttrDict
2727

2828
if TYPE_CHECKING:
2929
from .response.aggs import BucketData
@@ -137,9 +137,9 @@ def add_filter(self, filter_values: List[FilterValueType]) -> Optional[Query]:
137137
class RangeFacet(Facet[_R]):
138138
agg_type = "range"
139139

140-
def _range_to_dict(self, range: Tuple[Any, Tuple[int, int]]) -> Dict[str, JSONType]:
140+
def _range_to_dict(self, range: Tuple[Any, Tuple[int, int]]) -> Dict[str, Any]:
141141
key, _range = range
142-
out: Dict[str, JSONType] = {"key": key}
142+
out: Dict[str, Any] = {"key": key}
143143
if _range[0] is not None:
144144
out["from"] = _range[0]
145145
if _range[1] is not None:

elasticsearch_dsl/field.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
from .exceptions import ValidationException
3939
from .query import Q
40-
from .utils import AttrDict, AttrList, DslBase, JSONType
40+
from .utils import AttrDict, AttrList, DslBase
4141
from .wrappers import Range
4242

4343
if TYPE_CHECKING:
@@ -150,9 +150,9 @@ def clean(self, data: Any) -> Any:
150150
raise ValidationException("Value required for this field.")
151151
return data
152152

153-
def to_dict(self) -> Dict[str, JSONType]:
153+
def to_dict(self) -> Dict[str, Any]:
154154
d = super().to_dict()
155-
name, value = cast(Tuple[str, Dict[str, JSONType]], d.popitem())
155+
name, value = cast(Tuple[str, Dict[str, Any]], d.popitem())
156156
value["type"] = name
157157
return value
158158

@@ -161,7 +161,7 @@ class CustomField(Field):
161161
name = "custom"
162162
_coerce = True
163163

164-
def to_dict(self) -> Dict[str, JSONType]:
164+
def to_dict(self) -> Dict[str, Any]:
165165
if isinstance(self.builtin_type, Field):
166166
return self.builtin_type.to_dict()
167167

elasticsearch_dsl/function.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from copy import deepcopy
2020
from typing import Any, ClassVar, Dict, MutableMapping, Optional, Union, overload
2121

22-
from .utils import DslBase, JSONType
22+
from .utils import DslBase
2323

2424

2525
@overload
@@ -89,7 +89,7 @@ class ScoreFunction(DslBase):
8989
}
9090
name: ClassVar[Optional[str]] = None
9191

92-
def to_dict(self) -> Dict[str, JSONType]:
92+
def to_dict(self) -> Dict[str, Any]:
9393
d = super().to_dict()
9494
# filter and query dicts should be at the same level as us
9595
for k in self._param_defs:
@@ -107,7 +107,7 @@ class ScriptScore(ScoreFunction):
107107
class BoostFactor(ScoreFunction):
108108
name = "boost_factor"
109109

110-
def to_dict(self) -> Dict[str, JSONType]:
110+
def to_dict(self) -> Dict[str, Any]:
111111
d = super().to_dict()
112112
if self.name is not None:
113113
val = d[self.name]

elasticsearch_dsl/mapping_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from typing_extensions import Self
2323

2424
from .field import Field, Nested, Text, construct_field
25-
from .utils import DslBase, JSONType
25+
from .utils import DslBase
2626

2727
META_FIELDS = frozenset(
2828
(
@@ -205,7 +205,7 @@ def meta(self, name: str, params: Any = None, **kwargs: Any) -> Self:
205205
self._meta[name] = kwargs if params is None else params
206206
return self
207207

208-
def to_dict(self) -> Dict[str, JSONType]:
208+
def to_dict(self) -> Dict[str, Any]:
209209
meta = self._meta
210210

211211
# hard coded serialization of analyzers in _all

elasticsearch_dsl/response/__init__.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
cast,
2929
)
3030

31-
from ..utils import _R, AttrDict, AttrList, JSONType, _wrap
31+
from ..utils import _R, AttrDict, AttrList, _wrap
3232
from .hit import Hit, HitMeta
3333

3434
if TYPE_CHECKING:
@@ -40,7 +40,7 @@
4040
__all__ = ["Response", "AggResponse", "UpdateByQueryResponse", "Hit", "HitMeta"]
4141

4242

43-
class Response(AttrDict[JSONType], Generic[_R]):
43+
class Response(AttrDict[Any], Generic[_R]):
4444
_search: "SearchBase[_R]"
4545
_faceted_search: "FacetedSearchBase[_R]"
4646
_doc_class: Optional[_R]
@@ -92,7 +92,7 @@ def success(self) -> bool:
9292
@property
9393
def hits(self) -> List[_R]:
9494
if not hasattr(self, "_hits"):
95-
h = cast(AttrDict[JSONType], self._d_["hits"])
95+
h = cast(AttrDict[Any], self._d_["hits"])
9696

9797
try:
9898
hits = AttrList(list(map(self._search._get_result, h["hits"])))
@@ -116,7 +116,7 @@ def aggs(self) -> "AggResponse[_R]":
116116
aggs = AggResponse[_R](
117117
cast("Agg[_R]", self._search.aggs),
118118
self._search,
119-
cast(Dict[str, JSONType], self._d_.get("aggregations", {})),
119+
cast(Dict[str, Any], self._d_.get("aggregations", {})),
120120
)
121121

122122
# avoid assigning _aggs into self._d_
@@ -156,12 +156,10 @@ def search_after(self) -> "SearchBase[_R]":
156156
return self._search.extra(search_after=self.hits[-1].meta.sort) # type: ignore
157157

158158

159-
class AggResponse(AttrDict[JSONType], Generic[_R]):
159+
class AggResponse(AttrDict[Any], Generic[_R]):
160160
_meta: Dict[str, Any]
161161

162-
def __init__(
163-
self, aggs: "Agg[_R]", search: "Request[_R]", data: Dict[str, JSONType]
164-
):
162+
def __init__(self, aggs: "Agg[_R]", search: "Request[_R]", data: Dict[str, Any]):
165163
super(AttrDict, self).__setattr__("_meta", {"search": search, "aggs": aggs})
166164
super().__init__(data)
167165

@@ -177,7 +175,7 @@ def __iter__(self) -> Iterator["Agg"]: # type: ignore[override]
177175
yield self[name]
178176

179177

180-
class UpdateByQueryResponse(AttrDict[JSONType], Generic[_R]):
178+
class UpdateByQueryResponse(AttrDict[Any], Generic[_R]):
181179
_search: "UpdateByQueryBase[_R]"
182180

183181
def __init__(

elasticsearch_dsl/response/aggs.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Union, cast
1919

20-
from ..utils import _R, AttrDict, AttrList, JSONType
20+
from ..utils import _R, AttrDict, AttrList
2121
from . import AggResponse, Response
2222

2323
if TYPE_CHECKING:
@@ -31,7 +31,7 @@ def __init__(
3131
self,
3232
aggs: "Agg[_R]",
3333
search: "SearchBase[_R]",
34-
data: Dict[str, JSONType],
34+
data: Dict[str, Any],
3535
field: Optional["Field"] = None,
3636
):
3737
super().__init__(aggs, search, data)
@@ -42,7 +42,7 @@ def __init__(
4242
self,
4343
aggs: "Agg[_R]",
4444
search: "SearchBase[_R]",
45-
data: Dict[str, JSONType],
45+
data: Dict[str, Any],
4646
field: Optional["Field"] = None,
4747
):
4848
if field:
@@ -52,9 +52,9 @@ def __init__(
5252

5353
class BucketData(AggResponse[_R]):
5454
_bucket_class = Bucket
55-
_buckets: Union[AttrDict[JSONType], AttrList]
55+
_buckets: Union[AttrDict[Any], AttrList]
5656

57-
def _wrap_bucket(self, data: Dict[str, JSONType]) -> Bucket[_R]:
57+
def _wrap_bucket(self, data: Dict[str, Any]) -> Bucket[_R]:
5858
return self._bucket_class(
5959
self._meta["aggs"],
6060
self._meta["search"],
@@ -74,16 +74,16 @@ def __getitem__(self, key: Any) -> Any:
7474
return super().__getitem__(key)
7575

7676
@property
77-
def buckets(self) -> Union[AttrDict[JSONType], AttrList]:
77+
def buckets(self) -> Union[AttrDict[Any], AttrList]:
7878
if not hasattr(self, "_buckets"):
7979
field = getattr(self._meta["aggs"], "field", None)
8080
if field:
8181
self._meta["field"] = self._meta["search"]._resolve_field(field)
82-
bs = cast(Union[Dict[str, JSONType], List[JSONType]], self._d_["buckets"])
82+
bs = cast(Union[Dict[str, Any], List[Any]], self._d_["buckets"])
8383
if isinstance(bs, list):
8484
ret = AttrList(bs, obj_wrapper=self._wrap_bucket)
8585
else:
86-
ret = AttrDict[JSONType]({k: self._wrap_bucket(bs[k]) for k in bs}) # type: ignore
86+
ret = AttrDict[Any]({k: self._wrap_bucket(bs[k]) for k in bs}) # type: ignore
8787
super(AttrDict, self).__setattr__("_buckets", ret)
8888
return self._buckets
8989

0 commit comments

Comments
 (0)