Skip to content

Commit 8f99e3d

Browse files
simplify casts
1 parent d2164c0 commit 8f99e3d

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

elasticsearch_dsl/wrappers.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ def __init__(
6767
"Range accepts a single dictionary or a set of keyword arguments."
6868
)
6969

70-
# Cast here since mypy is inferring d as an `object` type for some reason
71-
data = cast(Dict[str, RangeValT], d) if d is not None else kwargs
70+
if d is None:
71+
data = cast(Dict[ComparisonOperators, RangeValT], kwargs)
72+
else:
73+
data = d
7274

7375
for k in data:
7476
if k not in self.OPS:
@@ -80,9 +82,7 @@ def __init__(
8082
if "lt" in data and "lte" in data:
8183
raise ValueError("You cannot specify both lt and lte for Range.")
8284

83-
# Here we use cast() since we now the keys are in the allowed values, but mypy does
84-
# not infer it.
85-
super().__init__(cast(Dict[ComparisonOperators, RangeValT], data))
85+
super().__init__(data)
8686

8787
def __repr__(self) -> str:
8888
return "Range(%s)" % ", ".join("%s=%r" % op for op in self._d_.items())
@@ -95,12 +95,8 @@ def __contains__(self, item: object) -> bool:
9595
if not item_supports_comp:
9696
return False
9797

98-
# Cast to tell mypy whe have checked it and its ok to use the comparison methods
99-
# on `item`
100-
item = cast("_SupportsComparison", item)
101-
10298
for op in self.OPS:
103-
if op in self._d_ and not self.OPS[op](item, self._d_[op]):
99+
if op in self._d_ and not self.OPS[op](cast("_SupportsComparison", item), self._d_[op]):
104100
return False
105101
return True
106102

0 commit comments

Comments
 (0)