Skip to content

Commit

Permalink
fix(type hints): Remove NotImplemented as type hints as not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
binste committed Aug 13, 2023
1 parent e6a0037 commit 1d1176d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 36 deletions.
4 changes: 1 addition & 3 deletions ibis/expr/types/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,7 @@ def as_table(self) -> ir.Table:
raise NotImplementedError(type(self))


def _binop(
op_class: type[ops.Binary], left: ir.Value, right: ir.Value
) -> ir.Value | NotImplemented:
def _binop(op_class: type[ops.Binary], left: ir.Value, right: ir.Value) -> ir.Value:
"""Try to construct a binary operation.
Parameters
Expand Down
36 changes: 18 additions & 18 deletions ibis/expr/types/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,25 +654,25 @@ def tan(self) -> NumericValue:
"""
return ops.Tan(self).to_expr()

def __add__(self, other: NumericValue) -> NumericValue | NotImplemented:
def __add__(self, other: NumericValue) -> NumericValue:
"""Add `self` with `other`."""
return _binop(ops.Add, self, other)

add = radd = __radd__ = __add__

def __sub__(self, other: NumericValue) -> NumericValue | NotImplemented:
def __sub__(self, other: NumericValue) -> NumericValue:
"""Subtract `other` from `self`."""
return _binop(ops.Subtract, self, other)

sub = __sub__

def __rsub__(self, other: NumericValue) -> NumericValue | NotImplemented:
def __rsub__(self, other: NumericValue) -> NumericValue:
"""Subtract `self` from `other`."""
return _binop(ops.Subtract, other, self)

rsub = __rsub__

def __mul__(self, other: NumericValue) -> NumericValue | NotImplemented:
def __mul__(self, other: NumericValue) -> NumericValue:
"""Multiply `self` and `other`."""
return _binop(ops.Multiply, self, other)

Expand All @@ -684,7 +684,7 @@ def __truediv__(self, other):

div = __div__ = __truediv__

def __rtruediv__(self, other: NumericValue) -> NumericValue | NotImplemented:
def __rtruediv__(self, other: NumericValue) -> NumericValue:
"""Divide `other` by `self`."""
return _binop(ops.Divide, other, self)

Expand All @@ -693,7 +693,7 @@ def __rtruediv__(self, other: NumericValue) -> NumericValue | NotImplemented:
def __floordiv__(
self,
other: NumericValue,
) -> NumericValue | NotImplemented:
) -> NumericValue:
"""Floor divide `self` by `other`."""
return _binop(ops.FloorDivide, self, other)

Expand All @@ -702,31 +702,31 @@ def __floordiv__(
def __rfloordiv__(
self,
other: NumericValue,
) -> NumericValue | NotImplemented:
) -> NumericValue:
"""Floor divide `other` by `self`."""
return _binop(ops.FloorDivide, other, self)

rfloordiv = __rfloordiv__

def __pow__(self, other: NumericValue) -> NumericValue | NotImplemented:
def __pow__(self, other: NumericValue) -> NumericValue:
"""Raise `self` to the `other`th power."""
return _binop(ops.Power, self, other)

pow = __pow__

def __rpow__(self, other: NumericValue) -> NumericValue | NotImplemented:
def __rpow__(self, other: NumericValue) -> NumericValue:
"""Raise `other` to the `self`th power."""
return _binop(ops.Power, other, self)

rpow = __rpow__

def __mod__(self, other: NumericValue) -> NumericValue | NotImplemented:
def __mod__(self, other: NumericValue) -> NumericValue:
"""Compute `self` modulo `other`."""
return _binop(ops.Modulus, self, other)

mod = __mod__

def __rmod__(self, other: NumericValue) -> NumericValue | NotImplemented:
def __rmod__(self, other: NumericValue) -> NumericValue:
"""Compute `other` modulo `self`."""

return _binop(ops.Modulus, other, self)
Expand Down Expand Up @@ -1102,37 +1102,37 @@ def convert_base(
"""
return ops.BaseConvert(self, from_base, to_base).to_expr()

def __and__(self, other: IntegerValue) -> IntegerValue | NotImplemented:
def __and__(self, other: IntegerValue) -> IntegerValue:
"""Bitwise and `self` with `other`."""
return _binop(ops.BitwiseAnd, self, other)

__rand__ = __and__

def __or__(self, other: IntegerValue) -> IntegerValue | NotImplemented:
def __or__(self, other: IntegerValue) -> IntegerValue:
"""Bitwise or `self` with `other`."""
return _binop(ops.BitwiseOr, self, other)

__ror__ = __or__

def __xor__(self, other: IntegerValue) -> IntegerValue | NotImplemented:
def __xor__(self, other: IntegerValue) -> IntegerValue:
"""Bitwise xor `self` with `other`."""
return _binop(ops.BitwiseXor, self, other)

__rxor__ = __xor__

def __lshift__(self, other: IntegerValue) -> IntegerValue | NotImplemented:
def __lshift__(self, other: IntegerValue) -> IntegerValue:
"""Bitwise left shift `self` with `other`."""
return _binop(ops.BitwiseLeftShift, self, other)

def __rlshift__(self, other: IntegerValue) -> IntegerValue | NotImplemented:
def __rlshift__(self, other: IntegerValue) -> IntegerValue:
"""Bitwise left shift `self` with `other`."""
return _binop(ops.BitwiseLeftShift, other, self)

def __rshift__(self, other: IntegerValue) -> IntegerValue | NotImplemented:
def __rshift__(self, other: IntegerValue) -> IntegerValue:
"""Bitwise right shift `self` with `other`."""
return _binop(ops.BitwiseRightShift, self, other)

def __rrshift__(self, other: IntegerValue) -> IntegerValue | NotImplemented:
def __rrshift__(self, other: IntegerValue) -> IntegerValue:
"""Bitwise right shift `self` with `other`."""
return _binop(ops.BitwiseRightShift, other, self)

Expand Down
2 changes: 1 addition & 1 deletion ibis/expr/types/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ def convert_base(
"""
return ops.BaseConvert(self, from_base, to_base).to_expr()

def __mul__(self, n: int | ir.IntegerValue) -> StringValue | NotImplemented:
def __mul__(self, n: int | ir.IntegerValue) -> StringValue:
return _binop(ops.Repeat, self, n)

__rmul__ = __mul__
Expand Down
28 changes: 14 additions & 14 deletions ibis/expr/types/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def truncate(
def __add__(
self,
other: datetime.timedelta | pd.Timedelta | IntervalValue,
) -> TimeValue | NotImplemented:
) -> TimeValue:
"""Add an interval to a time expression."""
return _binop(ops.TimeAdd, self, other)

Expand All @@ -224,7 +224,7 @@ def __add__(
Returns
-------
Value : TimeValue | NotImplemented
Value : TimeValue
"""

@annotated
Expand All @@ -248,7 +248,7 @@ def __sub__(self, other: ops.Value[dt.Interval | dt.Time, ds.Any]):
Returns
-------
Value : IntervalValue | TimeValue | NotImplemented
Value : IntervalValue | TimeValue
"""

@annotated
Expand Down Expand Up @@ -295,7 +295,7 @@ def truncate(self, unit: Literal["Y", "Q", "M", "W", "D"]) -> DateValue:
def __add__(
self,
other: datetime.timedelta | pd.Timedelta | IntervalValue,
) -> DateValue | NotImplemented:
) -> DateValue:
"""Add an interval to a date."""
return _binop(ops.DateAdd, self, other)

Expand All @@ -309,7 +309,7 @@ def __add__(
Returns
-------
Value : DateValue | NotImplemented
Value : DateValue
"""

@annotated
Expand All @@ -333,7 +333,7 @@ def __sub__(self, other: ops.Value[dt.Date | dt.Interval, ds.Any]):
Returns
-------
Value : DateValue | NotImplemented
Value : DateValue
"""

@annotated
Expand Down Expand Up @@ -393,7 +393,7 @@ def date(self) -> DateValue:
def __add__(
self,
other: datetime.timedelta | pd.Timedelta | IntervalValue,
) -> TimestampValue | NotImplemented:
) -> TimestampValue:
"""Add an interval to a timestamp."""
return _binop(ops.TimestampAdd, self, other)

Expand All @@ -407,7 +407,7 @@ def __add__(
Returns
-------
Value : TimestampValue | NotImplemented
Value : TimestampValue
"""

@annotated
Expand All @@ -431,7 +431,7 @@ def __sub__(self, other: ops.Value[dt.Timestamp | dt.Interval, ds.Any]):
Returns
-------
Value : IntervalValue | TimestampValue | NotImplemented
Value : IntervalValue | TimestampValue
"""

@annotated
Expand Down Expand Up @@ -537,7 +537,7 @@ def nanoseconds(self) -> ir.IntegerValue:
def __add__(
self,
other: datetime.timedelta | pd.Timedelta | IntervalValue,
) -> IntervalValue | NotImplemented:
) -> IntervalValue:
"""Add this interval to `other`."""
return _binop(ops.IntervalAdd, self, other)

Expand All @@ -546,7 +546,7 @@ def __add__(
def __sub__(
self,
other: datetime.timedelta | pd.Timedelta | IntervalValue,
) -> IntervalValue | NotImplemented:
) -> IntervalValue:
"""Subtract `other` from this interval."""
return _binop(ops.IntervalSubtract, self, other)

Expand All @@ -555,7 +555,7 @@ def __sub__(
def __rsub__(
self,
other: datetime.timedelta | pd.Timedelta | IntervalValue,
) -> IntervalValue | NotImplemented:
) -> IntervalValue:
"""Subtract `other` from this interval."""
return _binop(ops.IntervalSubtract, other, self)

Expand All @@ -564,7 +564,7 @@ def __rsub__(
def __mul__(
self,
other: int | ir.IntegerValue,
) -> IntervalValue | NotImplemented:
) -> IntervalValue:
"""Multiply this interval by `other`."""
return _binop(ops.IntervalMultiply, self, other)

Expand All @@ -573,7 +573,7 @@ def __mul__(
def __floordiv__(
self,
other: ir.IntegerValue,
) -> IntervalValue | NotImplemented:
) -> IntervalValue:
"""Floor-divide this interval by `other`."""
return _binop(ops.IntervalFloorDivide, self, other)

Expand Down

0 comments on commit 1d1176d

Please sign in to comment.