Skip to content

Commit

Permalink
Merge pull request #1287 from skirpichev/misc
Browse files Browse the repository at this point in the history
Enable 'no-else-return' error from pylint
  • Loading branch information
skirpichev committed Feb 1, 2023
2 parents f903c2c + 3e0d971 commit 051c1a8
Show file tree
Hide file tree
Showing 180 changed files with 3,606 additions and 4,645 deletions.
38 changes: 17 additions & 21 deletions diofant/calculus/gruntz.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ def compare(a, b, x):
c = limitinf(la/lb, x)
if c.is_zero:
return -1
elif c.is_infinite:
if c.is_infinite:
return 1
else:
return 0
return 0


def mrv(e, x):
Expand All @@ -115,27 +114,25 @@ def mrv(e, x):

if not e.has(x):
return set()
elif e == x:
if e == x:
return {x}
elif e.is_Mul or e.is_Add:
if e.is_Mul or e.is_Add:
a, b = e.as_two_terms()
return _mrv_max(mrv(a, x), mrv(b, x), x)
elif e.is_Exp:
if e.is_Exp:
if e.exp == x:
return {e}
elif any(a.is_infinite for a in Mul.make_args(limitinf(e.exp, x))):
if any(a.is_infinite for a in Mul.make_args(limitinf(e.exp, x))):
return _mrv_max({e}, mrv(e.exp, x), x)
else:
return mrv(e.exp, x)
elif e.is_Pow:
return mrv(e.exp, x)
if e.is_Pow:
return mrv(e.base, x)
elif isinstance(e, log):
if isinstance(e, log):
return mrv(e.args[0], x)
elif e.is_Function and not isinstance(e.func, UndefinedFunction):
if e.is_Function and not isinstance(e.func, UndefinedFunction):
return functools.reduce(lambda a, b: _mrv_max(a, b, x),
[mrv(a, x) for a in e.args])
else:
raise NotImplementedError(f"Can't calculate the MRV of {e}.")
raise NotImplementedError(f"Can't calculate the MRV of {e}.")


def _mrv_max(f, g, x):
Expand Down Expand Up @@ -164,12 +161,12 @@ def signinf(e, x):

if not e.has(x):
return sign(e).simplify()
elif e == x:
if e == x:
return Integer(1)
elif e.is_Mul:
if e.is_Mul:
a, b = e.as_two_terms()
return signinf(a, x)*signinf(b, x)
elif e.is_Pow and signinf(e.base, x) == 1:
if e.is_Pow and signinf(e.base, x) == 1:
return Integer(1)

c0, _ = leadterm(e, x)
Expand Down Expand Up @@ -202,12 +199,11 @@ def limitinf(e, x):
sig = signinf(e0, x)
if sig == 1:
return Integer(0)
elif sig == -1:
if sig == -1:
return signinf(c0, x)*oo
elif sig == 0:
if sig == 0:
return limitinf(c0, x)
else:
raise NotImplementedError(f'Result depends on the sign of {sig}.')
raise NotImplementedError(f'Result depends on the sign of {sig}.')


@cacheit
Expand Down
6 changes: 2 additions & 4 deletions diofant/calculus/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ def minimize_univariate(f, x, dom):
m = Min(limit(f, x, s), limit(f, x, s, dir=1))
if m == -oo:
return -oo, dict({x: s})
else:
extr[s] = m
extr[s] = m

for p in solve(diff(f, x), x):
p = p[x]
Expand Down Expand Up @@ -209,8 +208,7 @@ def solve_simplex(tableau, basis, phase1=False):

if tableau[row, col] <= 0:
return 1
else:
basis[row] = col
basis[row] = col

tableau[row, :] /= tableau[row, col]
for r in range(tableau.rows):
Expand Down
11 changes: 4 additions & 7 deletions diofant/calculus/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ def __new__(cls, expr, *args, **kwargs):
new_vp[v] = p
if set(expr_vp) == set(new_vp):
return expr
else:
variables = list(new_vp)
point = [new_vp[v] for v in variables]
variables = list(new_vp)
point = [new_vp[v] for v in variables]

if expr is nan:
return nan
Expand Down Expand Up @@ -241,15 +240,13 @@ def expr(self):
def variables(self):
if self.args[1:]:
return tuple(x[0] for x in self.args[1:])
else:
return ()
return ()

@property
def point(self):
if self.args[1:]:
return tuple(x[1] for x in self.args[1:])
else:
return ()
return ()

@property
def free_symbols(self):
Expand Down
4 changes: 2 additions & 2 deletions diofant/calculus/singularities.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def singularities(f, x):

if f.is_number:
return set()
elif f.is_polynomial(x):
if f.is_polynomial(x):
return set()
elif f.func in (Add, Mul):
if f.func in (Add, Mul):
guess = guess.union(*[singularities(a, x) for a in f.args])
elif isinstance(f, Pow):
if f.exp.is_number and f.exp.is_negative:
Expand Down
5 changes: 2 additions & 3 deletions diofant/combinatorics/partitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,10 +637,9 @@ def RGS_enum(m):
"""
if m < 1:
return 0
elif m == 1:
if m == 1:
return 1
else:
return bell(m)
return bell(m)


def RGS_unrank(rank, m):
Expand Down
62 changes: 26 additions & 36 deletions diofant/combinatorics/perm_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,10 +809,10 @@ def prop(g):
[rmul(gen, g) for gen in other.generators]
return self.subgroup_search(prop, base=base,
strong_gens=strong_gens, tests=tests)
elif hasattr(other, '__getitem__'):
if hasattr(other, '__getitem__'):
gens = list(other)
return self.centralizer(PermutationGroup(gens))
elif hasattr(other, 'array_form'):
if hasattr(other, 'array_form'):
return self.centralizer(PermutationGroup([other]))

def commutator(self, G, H):
Expand Down Expand Up @@ -1008,8 +1008,7 @@ def coset_unrank(self, rank, af=False):
h = _af_rmuln(*a)
if af:
return h
else:
return _af_new(h)
return _af_new(h)

@property
def degree(self):
Expand Down Expand Up @@ -1185,10 +1184,9 @@ def generate(self, method='coset', af=False):
"""
if method == 'coset':
return self.generate_schreier_sims(af)
elif method == 'dimino':
if method == 'dimino':
return self.generate_dimino(af)
else:
raise NotImplementedError(f'No generation defined for {method}')
raise NotImplementedError(f'No generation defined for {method}')

def generate_dimino(self, af=False):
"""Yield group elements using Dimino's algorithm
Expand Down Expand Up @@ -1479,12 +1477,11 @@ def is_alt_sym(self, eps=0.05, _random_prec=None):
if _check_cycles_alt_sym(perm):
return True
return False
else:
for i in range(_random_prec['N_eps']):
perm = _random_prec[i]
if _check_cycles_alt_sym(perm):
return True
return False
for i in range(_random_prec['N_eps']):
perm = _random_prec[i]
if _check_cycles_alt_sym(perm):
return True
return False

@property
def is_nilpotent(self):
Expand Down Expand Up @@ -1521,11 +1518,9 @@ def is_nilpotent(self):
self._is_solvable = True
self._is_nilpotent = True
return True
else:
self._is_nilpotent = False
return False
else:
return self._is_nilpotent
self._is_nilpotent = False
return False
return self._is_nilpotent

def is_normal(self, gr, strict=True):
"""Test if G=self is a normal subgroup of gr.
Expand Down Expand Up @@ -1649,11 +1644,9 @@ def is_solvable(self):
if all(g == identity for g in gens):
self._is_solvable = True
return True
else:
self._is_solvable = False
return False
else:
return self._is_solvable
self._is_solvable = False
return False
return self._is_solvable

def is_subgroup(self, G, strict=True):
"""Return True if all elements of self belong to G.
Expand Down Expand Up @@ -2021,9 +2014,9 @@ def normal_closure(self, other, k=10):
if _loop:
break
return Z
elif hasattr(other, '__getitem__'):
if hasattr(other, '__getitem__'):
return self.normal_closure(PermutationGroup(other))
elif hasattr(other, 'array_form'):
if hasattr(other, 'array_form'):
return self.normal_closure(PermutationGroup([other]))

def orbit(self, alpha, action='tuples'):
Expand Down Expand Up @@ -2094,8 +2087,7 @@ def orbit_rep(self, alpha, beta, schreier_vector=None):
k = schreier_vector[beta]
if a:
return _af_new(_af_rmuln(*a))
else:
return _af_new(list(range(self._degree)))
return _af_new(list(range(self._degree)))

def orbit_transversal(self, alpha, pairs=False):
r"""Computes a transversal for the orbit of ``alpha`` as a set.
Expand Down Expand Up @@ -2238,11 +2230,10 @@ def pointwise_stabilizer(self, points, incremental=True):
if not stab_gens:
stab_gens = _af_new(list(range(degree)))
return PermutationGroup(stab_gens)
else:
gens = self._generators
degree = self.degree
for x in points:
gens = _stabilizer(degree, gens, x)
gens = self._generators
degree = self.degree
for x in points:
gens = _stabilizer(degree, gens, x)
return PermutationGroup(gens)

def make_perm(self, n, seed=None):
Expand Down Expand Up @@ -3068,8 +3059,7 @@ def transitivity_degree(self):
G = G.stabilizer(i)
self._transitivity_degree = n
return n
else:
return self._transitivity_degree
return self._transitivity_degree


def _orbit(degree, generators, alpha, action='tuples'):
Expand Down Expand Up @@ -3120,7 +3110,7 @@ def _orbit(degree, generators, alpha, action='tuples'):
orb.append(temp)
used[temp] = True
return set(orb)
elif action == 'tuples':
if action == 'tuples':
alpha = tuple(alpha)
orb = [alpha]
used = {alpha}
Expand All @@ -3131,7 +3121,7 @@ def _orbit(degree, generators, alpha, action='tuples'):
orb.append(temp) # pylint: disable=modified-iterating-list
used.add(temp)
return set(orb)
elif action == 'sets':
if action == 'sets':
alpha = frozenset(alpha)
orb = [alpha]
used = {alpha}
Expand Down
27 changes: 12 additions & 15 deletions diofant/combinatorics/permutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def _af_pow(a, n):
return _af_pow(_af_invert(a), -n)
if n == 1:
return a[:]
elif n == 2:
if n == 2:
b = [a[i] for i in a]
elif n == 3:
b = [a[a[i]] for i in a]
Expand Down Expand Up @@ -415,7 +415,7 @@ def __init__(self, *args):
for c in args[0].cyclic_form:
self.update(self(*c))
return
elif isinstance(args[0], Cycle):
if isinstance(args[0], Cycle):
for k, v in args[0].items():
self[k] = v
return
Expand Down Expand Up @@ -826,7 +826,7 @@ def __new__(cls, *args, **kwargs):
ok = True
if not args: # a
return _af_new(list(range(size or 0)))
elif len(args) > 1: # c
if len(args) > 1: # c
return _af_new(Cycle(*args).list(size))
if len(args) == 1:
a = args[0]
Expand Down Expand Up @@ -1300,9 +1300,7 @@ def __rxor__(self, i):
"""
if int(i) == i:
return self(i)
else:
raise NotImplementedError(
f'i^p = p(i) when i is an integer, not {i}.')
raise NotImplementedError(f'i^p = p(i) when i is an integer, not {i}.')

def __xor__(self, h):
"""Return the conjugate permutation ``~h*self*h``.
Expand Down Expand Up @@ -1557,17 +1555,16 @@ def next_lex(self):
i -= 1
if i == -1:
return
else:
j = n - 1
while perm[j] < perm[i]:
j -= 1
j = n - 1
while perm[j] < perm[i]:
j -= 1
perm[j], perm[i] = perm[i], perm[j]
i += 1
j = n - 1
while i < j:
perm[j], perm[i] = perm[i], perm[j]
i += 1
j = n - 1
while i < j:
perm[j], perm[i] = perm[i], perm[j]
i += 1
j -= 1
j -= 1
return _af_new(perm)

@classmethod
Expand Down
7 changes: 3 additions & 4 deletions diofant/combinatorics/tensor_can.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,10 +1044,9 @@ def _get_bsgs(G, base, gens, free_indices):
"""Return the BSGS for G.pointwise_stabilizer(free_indices)."""
if not free_indices:
return base[:], gens[:]
else:
H = G.pointwise_stabilizer(free_indices)
base, sgs = H.schreier_sims_incremental()
return base, sgs
H = G.pointwise_stabilizer(free_indices)
base, sgs = H.schreier_sims_incremental()
return base, sgs

# if not base there is no slot symmetry for the component tensors
# if list_free_indices.count([]) < 2 there is no commutation symmetry
Expand Down
4 changes: 2 additions & 2 deletions diofant/combinatorics/testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def commutes_with_gens(x):
if commutes_with_gens(element):
centralizer_list.append(element)
return centralizer_list
elif hasattr(other, 'getitem'):
if hasattr(other, 'getitem'):
return _naive_list_centralizer(self, PermutationGroup(other), af)
elif hasattr(other, 'array_form'):
if hasattr(other, 'array_form'):
return _naive_list_centralizer(self, PermutationGroup([other]), af)


Expand Down

0 comments on commit 051c1a8

Please sign in to comment.