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]

0 commit comments

Comments
 (0)