Skip to content

Commit

Permalink
Remove NotImplementedType hints
Browse files Browse the repository at this point in the history
  • Loading branch information
binste committed Aug 13, 2023
1 parent 1035c01 commit c2fa860
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 41 deletions.
5 changes: 1 addition & 4 deletions ibis/expr/types/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
import webbrowser
from typing import TYPE_CHECKING, Any, Mapping, NoReturn, Tuple
from types import NotImplementedType

from public import public

Expand Down Expand Up @@ -545,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 | NotImplementedType:
def _binop(op_class: type[ops.Binary], left: ir.Value, right: ir.Value) -> ir.Value:
"""Try to construct a binary operation.
Parameters
Expand Down
39 changes: 19 additions & 20 deletions ibis/expr/types/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import collections
import functools
from typing import TYPE_CHECKING, Iterable, Literal, Sequence
from types import NotImplementedType

from public import public

Expand Down Expand Up @@ -655,25 +654,25 @@ def tan(self) -> NumericValue:
"""
return ops.Tan(self).to_expr()

def __add__(self, other: NumericValue) -> NumericValue | NotImplementedType:
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 | NotImplementedType:
def __sub__(self, other: NumericValue) -> NumericValue:
"""Subtract `other` from `self`."""
return _binop(ops.Subtract, self, other)

sub = __sub__

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

rsub = __rsub__

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

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

div = __div__ = __truediv__

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

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

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

rfloordiv = __rfloordiv__

def __pow__(self, other: NumericValue) -> NumericValue | NotImplementedType:
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 | NotImplementedType:
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 | NotImplementedType:
def __mod__(self, other: NumericValue) -> NumericValue:
"""Compute `self` modulo `other`."""
return _binop(ops.Modulus, self, other)

mod = __mod__

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

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

def __and__(self, other: IntegerValue) -> IntegerValue | NotImplementedType:
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 | NotImplementedType:
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 | NotImplementedType:
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 | NotImplementedType:
def __lshift__(self, other: IntegerValue) -> IntegerValue:
"""Bitwise left shift `self` with `other`."""
return _binop(ops.BitwiseLeftShift, self, other)

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

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

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

def __invert__(self) -> IntegerValue | NotImplementedType:
def __invert__(self) -> IntegerValue:
"""Bitwise not of `self`.
Returns
Expand Down
3 changes: 1 addition & 2 deletions ibis/expr/types/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import functools
import operator
from typing import TYPE_CHECKING, Any, Iterable, Literal, Sequence
from types import NotImplementedType

from public import public

Expand Down Expand Up @@ -1511,7 +1510,7 @@ def convert_base(
"""
return ops.BaseConvert(self, from_base, to_base).to_expr()

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

__rmul__ = __mul__
Expand Down
29 changes: 14 additions & 15 deletions ibis/expr/types/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import datetime
from typing import TYPE_CHECKING, Literal, Union
from types import NotImplementedType

from public import public

Expand Down Expand Up @@ -211,7 +210,7 @@ def truncate(
def __add__(
self,
other: datetime.timedelta | pd.Timedelta | IntervalValue,
) -> TimeValue | NotImplementedType:
) -> TimeValue:
"""Add an interval to a time expression."""
return _binop(ops.TimeAdd, self, other)

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

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

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

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

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

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

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

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

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

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

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

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

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

Expand Down

0 comments on commit c2fa860

Please sign in to comment.