variable type hints updated

This commit is contained in:
Nicolas Kruse 2025-12-01 00:12:22 +01:00
parent a8eeea874b
commit bb4472eccb
1 changed files with 37 additions and 11 deletions

View File

@ -104,6 +104,8 @@ class variable(Generic[TNum], Net):
self.source = CPConstant(source) self.source = CPConstant(source)
self.dtype = 'int' self.dtype = 'int'
@overload
def __add__(self: 'variable[TNum]', other: 'variable[TNum] | TNum') -> 'variable[TNum]': ...
@overload @overload
def __add__(self: 'variable[int]', other: uniint) -> 'variable[int]': ... def __add__(self: 'variable[int]', other: uniint) -> 'variable[int]': ...
@overload @overload
@ -117,6 +119,8 @@ class variable(Generic[TNum], Net):
return self return self
return add_op('add', [self, other], True) return add_op('add', [self, other], True)
@overload
def __radd__(self: 'variable[TNum]', other: TNum) -> 'variable[TNum]': ...
@overload @overload
def __radd__(self: 'variable[int]', other: int) -> 'variable[int]': ... def __radd__(self: 'variable[int]', other: int) -> 'variable[int]': ...
@overload @overload
@ -126,6 +130,8 @@ class variable(Generic[TNum], Net):
return self return self
return add_op('add', [self, other], True) return add_op('add', [self, other], True)
@overload
def __sub__(self: 'variable[TNum]', other: 'variable[TNum] | TNum') -> 'variable[TNum]': ...
@overload @overload
def __sub__(self: 'variable[int]', other: uniint) -> 'variable[int]': ... def __sub__(self: 'variable[int]', other: uniint) -> 'variable[int]': ...
@overload @overload
@ -137,6 +143,8 @@ class variable(Generic[TNum], Net):
def __sub__(self, other: TVarNumb) -> Any: def __sub__(self, other: TVarNumb) -> Any:
return add_op('sub', [self, other]) return add_op('sub', [self, other])
@overload
def __rsub__(self: 'variable[TNum]', other: TNum) -> 'variable[TNum]': ...
@overload @overload
def __rsub__(self: 'variable[int]', other: int) -> 'variable[int]': ... def __rsub__(self: 'variable[int]', other: int) -> 'variable[int]': ...
@overload @overload
@ -144,6 +152,8 @@ class variable(Generic[TNum], Net):
def __rsub__(self, other: NumLike) -> Any: def __rsub__(self, other: NumLike) -> Any:
return add_op('sub', [other, self]) return add_op('sub', [other, self])
@overload
def __mul__(self: 'variable[TNum]', other: 'variable[TNum] | TNum') -> 'variable[TNum]': ...
@overload @overload
def __mul__(self: 'variable[int]', other: uniint) -> 'variable[int]': ... def __mul__(self: 'variable[int]', other: uniint) -> 'variable[int]': ...
@overload @overload
@ -155,6 +165,8 @@ class variable(Generic[TNum], Net):
def __mul__(self, other: TVarNumb) -> Any: def __mul__(self, other: TVarNumb) -> Any:
return add_op('mul', [self, other], True) return add_op('mul', [self, other], True)
@overload
def __rmul__(self: 'variable[TNum]', other: TNum) -> 'variable[TNum]': ...
@overload @overload
def __rmul__(self: 'variable[int]', other: int) -> 'variable[int]': ... def __rmul__(self: 'variable[int]', other: int) -> 'variable[int]': ...
@overload @overload
@ -168,6 +180,8 @@ class variable(Generic[TNum], Net):
def __rtruediv__(self, other: NumLike) -> 'variable[float]': def __rtruediv__(self, other: NumLike) -> 'variable[float]':
return add_op('div', [other, self]) return add_op('div', [other, self])
@overload
def __floordiv__(self: 'variable[TNum]', other: 'variable[TNum] | TNum') -> 'variable[TNum]': ...
@overload @overload
def __floordiv__(self: 'variable[int]', other: uniint) -> 'variable[int]': ... def __floordiv__(self: 'variable[int]', other: uniint) -> 'variable[int]': ...
@overload @overload
@ -179,6 +193,8 @@ class variable(Generic[TNum], Net):
def __floordiv__(self, other: TVarNumb) -> Any: def __floordiv__(self, other: TVarNumb) -> Any:
return add_op('floordiv', [self, other]) return add_op('floordiv', [self, other])
@overload
def __rfloordiv__(self: 'variable[TNum]', other: TNum) -> 'variable[TNum]': ...
@overload @overload
def __rfloordiv__(self: 'variable[int]', other: int) -> 'variable[int]': ... def __rfloordiv__(self: 'variable[int]', other: int) -> 'variable[int]': ...
@overload @overload
@ -187,7 +203,9 @@ class variable(Generic[TNum], Net):
return add_op('floordiv', [other, self]) return add_op('floordiv', [other, self])
def __neg__(self: TCPNum) -> TCPNum: def __neg__(self: TCPNum) -> TCPNum:
return cast(TCPNum, add_op('sub', [variable(0), self])) if self.dtype == 'int':
return cast(TCPNum, add_op('sub', [variable(0), self]))
return cast(TCPNum, add_op('sub', [variable(0.0), self]))
def __gt__(self, other: TVarNumb) -> 'variable[int]': def __gt__(self, other: TVarNumb) -> 'variable[int]':
ret = add_op('gt', [self, other]) ret = add_op('gt', [self, other])
@ -214,36 +232,44 @@ class variable(Generic[TNum], Net):
return variable(ret.source, dtype='bool') return variable(ret.source, dtype='bool')
@overload @overload
def __mod__(self, other: TCPNum) -> TCPNum: ... def __mod__(self: 'variable[TNum]', other: 'variable[TNum] | TNum') -> 'variable[TNum]': ...
@overload @overload
def __mod__(self: TCPNum, other: uniint) -> TCPNum: ... def __mod__(self: 'variable[int]', other: uniint) -> 'variable[int]': ...
@overload @overload
def __mod__(self, other: unifloat) -> 'variable[float]': ... def __mod__(self, other: unifloat) -> 'variable[float]': ...
@overload @overload
def __mod__(self, other: NumLike) -> 'variable[float] | variable[int]': ... def __mod__(self: 'variable[float]', other: NumLike) -> 'variable[float]': ...
def __mod__(self, other: NumLike) -> Any: @overload
def __mod__(self, other: TVarNumb) -> 'variable[float] | variable[int]': ...
def __mod__(self, other: TVarNumb) -> Any:
return add_op('mod', [self, other]) return add_op('mod', [self, other])
@overload @overload
def __rmod__(self: TCPNum, other: int) -> TCPNum: ... def __rmod__(self: 'variable[TNum]', other: TNum) -> 'variable[TNum]': ...
@overload
def __rmod__(self: 'variable[int]', other: int) -> 'variable[int]': ...
@overload @overload
def __rmod__(self, other: float) -> 'variable[float]': ... def __rmod__(self, other: float) -> 'variable[float]': ...
def __rmod__(self, other: NumLike) -> Any: def __rmod__(self, other: NumLike) -> Any:
return add_op('mod', [other, self]) return add_op('mod', [other, self])
@overload @overload
def __pow__(self, other: TCPNum) -> TCPNum: ... def __pow__(self: 'variable[TNum]', other: 'variable[TNum] | TNum') -> 'variable[TNum]': ...
@overload @overload
def __pow__(self: TCPNum, other: uniint) -> TCPNum: ... def __pow__(self: 'variable[int]', other: uniint) -> 'variable[int]': ...
@overload @overload
def __pow__(self, other: unifloat) -> 'variable[float]': ... def __pow__(self, other: unifloat) -> 'variable[float]': ...
@overload @overload
def __pow__(self, other: NumLike) -> 'variable[float] | variable[int]': ... def __pow__(self: 'variable[float]', other: NumLike) -> 'variable[float]': ...
def __pow__(self, other: NumLike) -> Any: @overload
def __pow__(self, other: TVarNumb) -> 'variable[float] | variable[int]': ...
def __pow__(self, other: TVarNumb) -> Any:
return cp.pow(self, other) return cp.pow(self, other)
@overload @overload
def __rpow__(self: TCPNum, other: int) -> TCPNum: ... def __rpow__(self: 'variable[TNum]', other: TNum) -> 'variable[TNum]': ...
@overload
def __rpow__(self: 'variable[int]', other: int) -> 'variable[int]': ...
@overload @overload
def __rpow__(self, other: float) -> 'variable[float]': ... def __rpow__(self, other: float) -> 'variable[float]': ...
def __rpow__(self, other: NumLike) -> Any: def __rpow__(self, other: NumLike) -> Any: