Skip to content

Commit

Permalink
Fix sourcery suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
bleudev committed Nov 11, 2024
1 parent a69c0b0 commit f1bc370
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion ufpy/algebra/sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, *, iterable: Iterable[T]) -> None: ...
def __init__(self, *, iterable: Iterable[T], auto_update_U: bool) -> None: ...

def __init__(self, *values: T, iterable: Optional[Iterable[T]] = None, auto_update_U: bool = True) -> None:
if USet.U == None and auto_update_U:
if USet.U is None and auto_update_U:
USet.U = _U()

self.__set = list(sorted(set(iterable))) if iterable else list(sorted(set(values)))
Expand Down
55 changes: 27 additions & 28 deletions ufpy/math_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,37 @@
T = TypeVar('T')

def check(t: Type[T], s: str, astr: str):
s2 = f'__{astr}{s.replace('__', '')}__'
return s in t.__dict__ and s2 not in t.__dict__
return f'__{s}__' in t.__dict__ and f'__{astr}{s}__' not in t.__dict__

def i_generator(t: Type[T]) -> Type[T]:
def check_i(s: str):
return check(t, s, 'i')

if check_i('__add__'):
if check_i('add'):
t.__iadd__ = t.__add__
if check_i('__sub__'):
if check_i('sub'):
t.__isub__ = t.__sub__
if check_i('__mul__'):
if check_i('mul'):
t.__imul__ = t.__mul__
if check_i('__floordiv__'):
if check_i('floordiv'):
t.__ifloordiv__ = t.__floordiv__
if check_i('__div__'):
if check_i('div'):
t.__idiv__ = t.__div__
if check_i('__truediv__'):
if check_i('truediv'):
t.__itruediv__ = t.__truediv__
if check_i('__mod__'):
if check_i('mod'):
t.__imod__ = t.__mod__
if check_i('__pow__'):
if check_i('pow'):
t.__ipow__ = t.__pow__
if check_i('__lshift__'):
if check_i('lshift'):
t.__ilshift__ = t.__lshift__
if check_i('__rshift__'):
if check_i('rshift'):
t.__irshift__ = t.__rshift__
if check_i('__and__'):
if check_i('and'):
t.__iand__ = t.__and__
if check_i('__or__'):
if check_i('or'):
t.__ior__ = t.__or__
if check_i('__xor__'):
if check_i('xor'):
t.__ixor__ = t.__xor__

return t
Expand All @@ -49,31 +48,31 @@ def r_generator(t: Type[T]) -> Type[T]:
def check_r(s: str):
return check(t, s, 'r')

if check_r('__add__'):
if check_r('add'):
t.__radd__ = t.__add__
if check_r('__sub__'):
if check_r('sub'):
t.__rsub__ = t.__sub__
if check_r('__mul__'):
if check_r('mul'):
t.__rmul__ = t.__mul__
if check_r('__floordiv__'):
if check_r('floordiv'):
t.__rfloordiv__ = t.__floordiv__
if check_r('__div__'):
if check_r('div'):
t.__rdiv__ = t.__div__
if check_r('__truediv__'):
if check_r('truediv'):
t.__rtruediv__ = t.__truediv__
if check_r('__mod__'):
if check_r('mod'):
t.__rmod__ = t.__mod__
if check_r('__pow__'):
if check_r('pow'):
t.__rpow__ = t.__pow__
if check_r('__lshift__'):
if check_r('lshift'):
t.__rlshift__ = t.__lshift__
if check_r('__rshift__'):
if check_r('rshift'):
t.__rrshift__ = t.__rshift__
if check_r('__and__'):
if check_r('and'):
t.__rand__ = t.__and__
if check_r('__or__'):
if check_r('or'):
t.__ror__ = t.__or__
if check_r('__xor__'):
if check_r('xor'):
t.__rxor__ = t.__xor__

return t

0 comments on commit f1bc370

Please sign in to comment.