Skip to content

Commit

Permalink
Trac #34342: fix various suggestions by lgtm
Browse files Browse the repository at this point in the history
URL: https://trac.sagemath.org/34342
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): David Coudert
  • Loading branch information
Release Manager committed Sep 25, 2022
2 parents 1d51c7d + d5541fe commit 04fbc82
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 116 deletions.
6 changes: 3 additions & 3 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tarball=configure-VERSION.tar.gz
sha1=216e21528815b12e0c7afed7315cb527bfe663ee
md5=17835976684ddfb85014fcc85f10391c
cksum=664752095
sha1=5a1689117566cc63ea05f0aa9a2f125da7ba7dc6
md5=37178d28e02f691476b4ba5b9e915026
cksum=4153085574
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
93aa1c960c08b4de7808093835d684f165b8f30e
1cee2c8b179b9fb913facf54b48dd710178bbffc
5 changes: 2 additions & 3 deletions build/pkgs/matplotlib/make-setup-config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from configparser import ConfigParser
import pkgconfig
import os

config = ConfigParser()
Expand All @@ -23,7 +22,7 @@

print("NOTE: Set SAGE_MATPLOTLIB_GUI to anything but 'no' to try to build the Matplotlib GUI.")

graphical_backend='False'
graphical_backend = 'False'
if os.environ.get('SAGE_MATPLOTLIB_GUI', 'no').lower() != 'no':
graphical_backend = 'auto'

Expand All @@ -35,7 +34,7 @@

config.add_section('gui_support')
for backend in ('gtk', 'gtkagg', 'tkagg', 'wxagg', 'macosx', 'windowing'):
config.set('gui_support', backend, graphical_backend)
config.set('gui_support', backend, graphical_backend)

with open('src/mplsetup.cfg', 'w') as configfile:
config.write(configfile)
19 changes: 9 additions & 10 deletions src/sage/algebras/quatalg/quaternion_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -2690,15 +2690,13 @@ def multiply_by_conjugate(self, J):
R = self.quaternion_algebra()
return R.ideal(basis, check=False)

def is_equivalent(I, J, B=10):
def is_equivalent(self, J, B=10) -> bool:
"""
Return ``True`` if ``I`` and ``J`` are equivalent as right ideals.
Return ``True`` if ``self`` and ``J`` are equivalent as right ideals.
INPUT:
- ``I`` -- a fractional quaternion ideal (self)
- ``J`` -- a fractional quaternion ideal with same order as ``I``
- ``J`` -- a fractional quaternion ideal with same order as ``self``
- ``B`` -- a bound to compute and compare theta series before
doing the full equivalence test
Expand All @@ -2718,23 +2716,24 @@ def is_equivalent(I, J, B=10):
sage: R[0].is_equivalent(S)
True
"""
if not isinstance(I, QuaternionFractionalIdeal_rational):
# shorthand: let I be self
if not isinstance(self, QuaternionFractionalIdeal_rational):
return False

if I.right_order() != J.right_order():
raise ValueError("I and J must be right ideals")
if self.right_order() != J.right_order():
raise ValueError("self and J must be right ideals")

# Just test theta series first. If the theta series are
# different, the ideals are definitely not equivalent.
if B > 0 and I.theta_series_vector(B) != J.theta_series_vector(B):
if B > 0 and self.theta_series_vector(B) != J.theta_series_vector(B):
return False

# The theta series are the same, so perhaps the ideals are
# equivalent. We use Prop 1.18 of [Pizer, 1980] to decide.
# 1. Compute I * Jbar
# see Prop. 1.17 in Pizer. Note that we use IJbar instead of
# JbarI since we work with right ideals
IJbar = I.multiply_by_conjugate(J)
IJbar = self.multiply_by_conjugate(J)

# 2. Determine if there is alpha in K such
# that N(alpha) = N(I)*N(J) as explained by Pizer.
Expand Down
7 changes: 6 additions & 1 deletion src/sage/functions/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,7 @@ def _print_latex_(self, z, m):

harmonic_number = Function_harmonic_number_generalized()


class _Function_swap_harmonic(BuiltinFunction):
r"""
Harmonic number function with swapped arguments. For internal use only.
Expand All @@ -1262,14 +1263,18 @@ class _Function_swap_harmonic(BuiltinFunction):
"""
def __init__(self):
BuiltinFunction.__init__(self, "_swap_harmonic", nargs=2)

def _eval_(self, a, b, **kwds):
return harmonic_number(b,a,**kwds)
return harmonic_number(b, a, **kwds)


_swap_harmonic = _Function_swap_harmonic()


register_symbol(_swap_harmonic, {'maxima': 'gen_harmonic_number'})
register_symbol(_swap_harmonic, {'maple': 'harmonic'})


class Function_harmonic_number(BuiltinFunction):
r"""
Harmonic number function, defined by:
Expand Down
21 changes: 10 additions & 11 deletions src/sage/groups/abelian_gps/dual_abelian_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@
# http://www.gnu.org/licenses/
###########################################################################

from sage.rings.infinity import infinity
from sage.structure.category_object import normalize_names
from sage.structure.unique_representation import UniqueRepresentation
from sage.groups.abelian_gps.dual_abelian_group_element import (
DualAbelianGroupElement, is_DualAbelianGroupElement )
DualAbelianGroupElement, is_DualAbelianGroupElement)
from sage.misc.mrange import mrange
from sage.misc.cachefunc import cached_method
from sage.groups.group import AbelianGroup as AbelianGroupBase
Expand Down Expand Up @@ -126,7 +125,7 @@ def __init__(self, G, names, base_ring):
self._group = G
names = normalize_names(G.ngens(), names)
self._assign_names(names)
AbelianGroupBase.__init__(self) # TODO: category=CommutativeGroups()
AbelianGroupBase.__init__(self) # TODO: category=CommutativeGroups()

def group(self):
"""
Expand Down Expand Up @@ -165,7 +164,7 @@ def __str__(self):
sage: print(Fd)
DualAbelianGroup( AbelianGroup ( 3, (5, 64, 729) ) )
"""
s = "DualAbelianGroup( AbelianGroup ( %s, %s ) )"%(self.ngens(), self.gens_orders())
s = "DualAbelianGroup( AbelianGroup ( %s, %s ) )" % (self.ngens(), self.gens_orders())
return s

def _repr_(self):
Expand All @@ -188,9 +187,9 @@ def _repr_(self):
eldv = G.gens_orders()
gp = ""
for x in eldv:
if x!=0:
gp = gp + "Z/%sZ x "%x
if x==0:
if x != 0:
gp = gp + "Z/%sZ x " % x
if x == 0:
gp = gp + "Z x "
gp = gp[:-2].strip()
s = 'Dual of Abelian Group isomorphic to ' + gp + ' over ' + str(self.base_ring())
Expand Down Expand Up @@ -235,7 +234,7 @@ def random_element(self):
result = self.one()
for g in self.gens():
order = g.order()
result *= g**(randint(0,order))
result *= g**(randint(0, order))
return result

def gen(self, i=0):
Expand All @@ -255,8 +254,8 @@ def gen(self, i=0):
"""
n = self.group().ngens()
if i < 0 or i >= n:
raise IndexError("Argument i (= %s) must be between 0 and %s."%(i, n-1))
x = [0]*n
raise IndexError("Argument i (= %s) must be between 0 and %s." % (i, n - 1))
x = [0] * n
if self.gens_orders()[i] != 1:
x[i] = 1
return self.element_class(self, x)
Expand Down Expand Up @@ -324,7 +323,7 @@ def invariants(self):
# TODO: deprecate
return self.group().gens_orders()

def __contains__(self,X):
def __contains__(self, X):
"""
Implements "in".
Expand Down
10 changes: 4 additions & 6 deletions src/sage/interfaces/ecm.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 3 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
# https://www.gnu.org/licenses/
###############################################################################

import re
import subprocess
from subprocess import Popen, PIPE, call

from sage.structure.sage_object import SageObject
from sage.rings.integer_ring import ZZ
Expand Down Expand Up @@ -216,8 +216,6 @@ def _run_ecm(self, cmd, n):
sage: ecm._run_ecm(['cat'], 1234)
'1234'
"""
from subprocess import Popen, PIPE

# Under normal usage this program only returns ASCII; anything
# else mixed is garbage and an error
# So just accept latin-1 without encoding errors, and let the
Expand Down Expand Up @@ -261,7 +259,7 @@ def interact(self):
"""
print("Enter numbers to run ECM on them.")
print("Press control-D to exit.")
subprocess.call(self._cmd)
call(self._cmd)

# Recommended settings from
# http://www.mersennewiki.org/index.php/Elliptic_Curve_Method
Expand Down Expand Up @@ -661,7 +659,7 @@ def factor(self, n, factor_digits=None, B1=2000, proof=False, **kwds):
# Step 3: Call find_factor until a factorization is found
n_factorization = [n]
while len(n_factorization) == 1:
n_factorization = self.find_factor(n,B1=B1)
n_factorization = self.find_factor(n, B1=B1)
factors.extend(n_factorization)

return sorted(probable_prime_factors)
Expand Down
8 changes: 3 additions & 5 deletions src/sage/modules/quotient_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
# https://www.gnu.org/licenses/
# ****************************************************************************

from sage.structure.richcmp import rich_to_bool, richcmp

from .free_module import (Module_free_ambient,
FreeModule_ambient,
FreeModule_ambient_field)


###############################################################################
#
# Quotients of ambient free modules over a domain
Expand Down Expand Up @@ -80,7 +79,7 @@ def __init__(self, module, sub):
v = [C(self._free_cover, x.list(), coerce=False, copy=False) for x in sub.gens()]
w = [C(self._free_cover, x.list(), coerce=False, copy=False) for x in module.free_relations().gens()]
self._relations = self._free_cover.submodule(v + w, check=False)
else: # Otherwise module should be a free module
else: # Otherwise module should be a free module
self._free_cover = module
self._relations = sub

Expand Down Expand Up @@ -448,7 +447,7 @@ def _repr_(self):
sage: Q._repr_()
'Vector space quotient V/W of dimension 1 over Finite Field in a of size 3^2 where\nV: Vector space of degree 3 and dimension 2 over Finite Field in a of size 3^2\nUser basis matrix:\n[1 0 a]\n[a a 1]\nW: Vector space of degree 3 and dimension 1 over Finite Field in a of size 3^2\nBasis matrix:\n[ 1 1 a + 2]'
"""
return "%s space quotient V/W of dimension %s over %s where\nV: %s\nW: %s"%(
return "%s space quotient V/W of dimension %s over %s where\nV: %s\nW: %s" % (
"Sparse vector" if self.is_sparse() else "Vector",
self.dimension(), self.base_ring(),
self.V(), self.W())
Expand Down Expand Up @@ -675,4 +674,3 @@ def relations(self):
return self._sub

W = relations

Loading

0 comments on commit 04fbc82

Please sign in to comment.