From f1bc370252461ea9d73248edc0111961ed385b1e Mon Sep 17 00:00:00 2001 From: bleudev Date: Mon, 11 Nov 2024 22:45:20 +0300 Subject: [PATCH] Fix sourcery suggestions --- ufpy/algebra/sets.py | 2 +- ufpy/math_op.py | 55 ++++++++++++++++++++++---------------------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/ufpy/algebra/sets.py b/ufpy/algebra/sets.py index 5485c1f..eb690c9 100644 --- a/ufpy/algebra/sets.py +++ b/ufpy/algebra/sets.py @@ -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))) diff --git a/ufpy/math_op.py b/ufpy/math_op.py index 984fa66..27ffd36 100644 --- a/ufpy/math_op.py +++ b/ufpy/math_op.py @@ -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 @@ -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