@@ -67,8 +67,10 @@ def __init__(
67
67
"Range accepts a single dictionary or a set of keyword arguments."
68
68
)
69
69
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
72
74
73
75
for k in data :
74
76
if k not in self .OPS :
@@ -80,9 +82,7 @@ def __init__(
80
82
if "lt" in data and "lte" in data :
81
83
raise ValueError ("You cannot specify both lt and lte for Range." )
82
84
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 )
86
86
87
87
def __repr__ (self ) -> str :
88
88
return "Range(%s)" % ", " .join ("%s=%r" % op for op in self ._d_ .items ())
@@ -95,12 +95,8 @@ def __contains__(self, item: object) -> bool:
95
95
if not item_supports_comp :
96
96
return False
97
97
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
-
102
98
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 ]):
104
100
return False
105
101
return True
106
102
0 commit comments