Skip to content

Commit

Permalink
sagemathgh-36870: some ruff auto-fixes in schemes + error links in doc
Browse files Browse the repository at this point in the history
    
Some fixes made by ruff in the schemes folder (codes C4, UP02, UP009)

plus adding manually some links to errors in the doc

### 📝 Checklist

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
    
URL: sagemath#36870
Reported by: Frédéric Chapoton
Reviewer(s): Matthias Köppe
  • Loading branch information
Release Manager committed Dec 22, 2023
2 parents 92aeb3f + a5cd340 commit 4c656cc
Show file tree
Hide file tree
Showing 60 changed files with 128 additions and 151 deletions.
6 changes: 3 additions & 3 deletions src/sage/schemes/affine/affine_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ def rational_points(self, F=None):
if F is None:
if not isinstance(self.base_ring(), FiniteField):
raise TypeError("base ring (= %s) must be a finite field" % self.base_ring())
return [P for P in self]
return list(self)
elif not isinstance(F, FiniteField):
raise TypeError("second argument (= %s) must be a finite field" % F)
return [P for P in self.base_extend(F)]
return list(self.base_extend(F))

def __eq__(self, right):
"""
Expand Down Expand Up @@ -1226,7 +1226,7 @@ def translation(self, p, q=None):
if q is not None:
v = [cp - cq for cp, cq in zip(p, q)]
else:
v = [cp for cp in p]
v = list(p)

return self._morphism(self.Hom(self), [x - c for x, c in zip(gens, v)])

Expand Down
12 changes: 6 additions & 6 deletions src/sage/schemes/curves/affine_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,13 +684,13 @@ def tangents(self, P, factor=True):
if t > 0:
fact.append(vars[0])
# divide T by that power of vars[0]
T = self.ambient_space().coordinate_ring()(dict([((v[0] - t, v[1]), h) for (v, h) in T.dict().items()]))
T = self.ambient_space().coordinate_ring()({(v[0] - t, v[1]): h for (v, h) in T.dict().items()})
t = min([e[1] for e in T.exponents()])
# vars[1] divides T
if t > 0:
fact.append(vars[1])
# divide T by that power of vars[1]
T = self.ambient_space().coordinate_ring()(dict([((v[0], v[1] - t), h) for (v, h) in T.dict().items()]))
T = self.ambient_space().coordinate_ring()({(v[0], v[1] - t): h for (v, h) in T.dict().items()})
# T is homogeneous in var[0], var[1] if nonconstant, so dehomogenize
if T not in self.base_ring():
if T.degree(vars[0]) > 0:
Expand Down Expand Up @@ -1032,7 +1032,7 @@ def projection(self, indices, AS=None):
C = AA2.curve(G)
except (TypeError, ValueError):
C = AA2.subscheme(G)
return tuple([psi, C])
return (psi, C)

def plane_projection(self, AP=None):
r"""
Expand Down Expand Up @@ -1397,7 +1397,7 @@ def blowup(self, P=None):
homvars.insert(i, 1)
coords = [(p_A.gens()[0] - P[i])*homvars[j] + P[j] for j in range(n)]
proj_maps.append(H(coords))
return tuple([tuple(patches), tuple(t_maps), tuple(proj_maps)])
return (tuple(patches), tuple(t_maps), tuple(proj_maps))

def resolution_of_singularities(self, extend=False):
r"""
Expand Down Expand Up @@ -1688,7 +1688,7 @@ def extension(self):
patches = [res[i][0] for i in range(len(res))]
t_maps = [tuple(res[i][1]) for i in range(len(res))]
p_maps = [res[i][2] for i in range(len(res))]
return tuple([tuple(patches), tuple(t_maps), tuple(p_maps)])
return (tuple(patches), tuple(t_maps), tuple(p_maps))

def tangent_line(self, p):
"""
Expand Down Expand Up @@ -2600,7 +2600,7 @@ def places_at_infinity(self):
sage: C.places_at_infinity()
[Place (1/x, 1/x*z^2)]
"""
return list(set(p for f in self._coordinate_functions if f for p in f.poles()))
return list({p for f in self._coordinate_functions if f for p in f.poles()})

def places_on(self, point):
"""
Expand Down
6 changes: 3 additions & 3 deletions src/sage/schemes/curves/projective_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def projection(self, P=None, PS=None):
phi = K(l)
G = [phi(f) for f in J.gens()]
C = PP2.curve(G)
return tuple([psi, C])
return (psi, C)

def plane_projection(self, PP=None):
r"""
Expand Down Expand Up @@ -577,7 +577,7 @@ def plane_projection(self, PP=None):
psi = K(phi.defining_polynomials())
H = Hom(self, L[1].ambient_space())
phi = H([psi(L[0].defining_polynomials()[i]) for i in range(len(L[0].defining_polynomials()))])
return tuple([phi, C])
return (phi, C)


class ProjectivePlaneCurve(ProjectiveCurve):
Expand Down Expand Up @@ -1104,7 +1104,7 @@ def quadratic_transform(self):
T = []
for item in G.dict().items():
tup = tuple([item[0][i] - degs[i] for i in range(len(L))])
T.append(tuple([tup, item[1]]))
T.append((tup, item[1]))
G = R(dict(T))
H = Hom(self, PP.curve(G))
phi = H(coords)
Expand Down
8 changes: 4 additions & 4 deletions src/sage/schemes/curves/zariski_vankampen.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
from sage.rings.real_mpfr import RealField
# from sage.sets.set import Set

roots_interval_cache = dict()
roots_interval_cache = {}


def braid_from_piecewise(strands):
Expand Down Expand Up @@ -793,7 +793,7 @@ def populate_roots_interval_cache(inputs):


@parallel
def braid_in_segment(glist, x0, x1, precision=dict()):
def braid_in_segment(glist, x0, x1, precision={}):
"""
Return the braid formed by the `y` roots of ``f`` when `x` moves
from ``x0`` to ``x1``.
Expand Down Expand Up @@ -1711,7 +1711,7 @@ def fundamental_group_arrangement(flist, simplified=True, projective=False, puis
f = prod(flist1)
if len(flist1) == 0:
bm = []
dic = dict()
dic = {}
else:
bm, dic = braid_monodromy(f, flist1)
g = fundamental_group_from_braid_mon(bm, degree=d, simplified=False, projective=projective, puiseux=puiseux)
Expand All @@ -1721,7 +1721,7 @@ def fundamental_group_arrangement(flist, simplified=True, projective=False, puis
hom = g.hom(codomain=g, im_gens=list(g.gens()), check=False)
g1 = hom.codomain()
if len(flist) == 0:
return (g1, dict())
return (g1, {})
dic1 = {}
for i in range(len(flist1)):
L = [j1 for j1 in dic.keys() if dic[j1] == i]
Expand Down
4 changes: 2 additions & 2 deletions src/sage/schemes/cyclic_covers/cycliccover_finite_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ def _initialize_fat_vertical(self, s0, max_upper_target):
L = floor((max_upper_target - self._epsilon) / self._p) + 1
if s0 not in self._vertical_fat_s:
(m0, m1), (M0, M1) = self._vertical_matrix_reduction(s0)
D0, D1 = map(lambda y: matrix(self._Zq, [y]), [m0, m1])
D0, D1 = (matrix(self._Zq, [y]) for y in [m0, m1])
targets = [0] * (2 * L)
for l in reversed(range(L)):
targets[2 * l] = max_upper_target - self._p * (L - l)
Expand Down Expand Up @@ -1268,7 +1268,7 @@ def _denominator():
f = x ** self._delta - lc
L = f.splitting_field("a")
roots = [r for r, _ in f.change_ring(L).roots()]
roots_dict = dict([(r, i) for i, r in enumerate(roots)])
roots_dict = {r: i for i, r in enumerate(roots)}
rootsfrob = [L.frobenius_endomorphism(self._Fq.degree())(r) for r in roots]
m = zero_matrix(len(roots))
for i, r in enumerate(roots):
Expand Down
1 change: 0 additions & 1 deletion src/sage/schemes/elliptic_curves/BSD.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"Birch and Swinnerton-Dyer formulas"

from sage.arith.misc import prime_divisors
Expand Down
1 change: 0 additions & 1 deletion src/sage/schemes/elliptic_curves/Qcurves.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
r"""
Testing whether elliptic curves over number fields are `\QQ`-curves
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/elliptic_curves/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ def is_cm_j_invariant(j, algorithm='CremonaSutherland', method=None):

if j in ZZ:
j = ZZ(j)
table = dict([(jj,(d,f)) for d,f,jj in cm_j_invariants_and_orders(QQ)])
table = {jj: (d,f) for d,f,jj in cm_j_invariants_and_orders(QQ)}
if j in table:
return True, table[j]
return False, None
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/elliptic_curves/ec_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def rank(self, rank, tors=0, n=10, labels=False):
data = os.path.join(ELLCURVE_DATA_DIR, 'rank%s' % rank)
try:
f = open(data)
except IOError:
except OSError:
return []
v = []
tors = int(tors)
Expand Down
3 changes: 1 addition & 2 deletions src/sage/schemes/elliptic_curves/ell_curve_isogeny.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
r"""
Isogenies
Expand Down Expand Up @@ -1953,7 +1952,7 @@ def __sort_kernel_list(self):
"""
a1, a2, a3, a4, _ = self._domain.a_invariants()

self.__kernel_mod_sign = dict()
self.__kernel_mod_sign = {}
v = w = 0

for Q in self.__kernel_list:
Expand Down
8 changes: 4 additions & 4 deletions src/sage/schemes/elliptic_curves/ell_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def __init__(self, K, ainvs):
- (x**3 + a2*x**2*z + a4*x*z**2 + a6*z**3)
plane_curve.ProjectivePlaneCurve.__init__(self, PP, f)

self.__divpolys = (dict(), dict(), dict())
self.__divpolys = ({}, {}, {})

# See #1975: we deliberately set the class to
# EllipticCurvePoint_finite_field for finite rings, so that we
Expand Down Expand Up @@ -1732,7 +1732,7 @@ def division_polynomial_0(self, n, x=None):
x = polygen(self.base_ring())
else:
# For other inputs, we use a temporary cache.
cache = dict()
cache = {}

b2, b4, b6, b8 = self.b_invariants()

Expand Down Expand Up @@ -2119,7 +2119,7 @@ def _multiple_x_numerator(self, n, x=None):
try:
cache = self.__mulxnums
except AttributeError:
cache = self.__mulxnums = dict()
cache = self.__mulxnums = {}
try:
return cache[n]
except KeyError:
Expand Down Expand Up @@ -2216,7 +2216,7 @@ def _multiple_x_denominator(self, n, x=None):
try:
cache = self.__mulxdens
except AttributeError:
cache = self.__mulxdens = dict()
cache = self.__mulxdens = {}
try:
return cache[n]
except KeyError:
Expand Down
1 change: 0 additions & 1 deletion src/sage/schemes/elliptic_curves/ell_local_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
r"""
Local data for elliptic curves over number fields
Expand Down
1 change: 0 additions & 1 deletion src/sage/schemes/elliptic_curves/ell_modular_symbols.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
r"""
Modular symbols attached to elliptic curves over `\QQ`
Expand Down
5 changes: 2 additions & 3 deletions src/sage/schemes/elliptic_curves/ell_number_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,8 @@ def global_integral_model(self):
"""
K = self.base_field()
ai = self.a_invariants()
Ps = set(ff[0]
for a in ai if not a.is_integral()
for ff in a.denominator_ideal().factor())
Ps = {ff[0] for a in ai if not a.is_integral()
for ff in a.denominator_ideal().factor()}
for P in Ps:
pi = K.uniformizer(P, 'positive')
e = min((ai[i].valuation(P)/[1,2,3,4,6][i])
Expand Down
1 change: 0 additions & 1 deletion src/sage/schemes/elliptic_curves/ell_point.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
r"""
Points on elliptic curves
Expand Down
22 changes: 11 additions & 11 deletions src/sage/schemes/elliptic_curves/ell_rational_field.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
r"""
Elliptic curves over the rational numbers
Expand Down Expand Up @@ -1559,10 +1558,11 @@ def analytic_rank(self, algorithm="pari", leading_coefficient=False):
return self.analytic_rank_upper_bound()
elif algorithm == 'all':
if leading_coefficient:
S = set([self.analytic_rank('pari', True)])
S = {self.analytic_rank('pari', True)}
else:
S = set([self.analytic_rank('pari'),
self.analytic_rank('rubinstein'), self.analytic_rank('sympow')])
S = {self.analytic_rank('pari'),
self.analytic_rank('rubinstein'),
self.analytic_rank('sympow')}
if len(S) != 1:
raise RuntimeError("Bug in analytic_rank; algorithms don't agree! (E=%s)" % self)
return list(S)[0]
Expand Down Expand Up @@ -5347,10 +5347,10 @@ def _shortest_paths(self):
# Take logs here since shortest path minimizes the *sum* of the weights -- not the product.
M = M.parent()([a.log() if a else 0 for a in M.list()])
G = Graph(M, format='weighted_adjacency_matrix')
G.set_vertices(dict([(v,isocls[v]) for v in G.vertices(sort=False)]))
G.set_vertices({v: isocls[v] for v in G.vertices(sort=False)})
v = G.shortest_path_lengths(0, by_weight=True)
# Now exponentiate and round to get degrees of isogenies
v = dict([(i, j.exp().round() if j else 0) for i,j in v.items()])
v = {i: j.exp().round() if j else 0 for i,j in v.items()}
return isocls.curves, v

def _multiple_of_degree_of_isogeny_to_optimal_curve(self):
Expand Down Expand Up @@ -6179,7 +6179,7 @@ def point_preprocessing(free,tor):
subgroup of index 2.
"""
r = len(free)
newfree = [Q for Q in free] # copy
newfree = list(free) # copy
tor_egg = [T for T in tor if not T.is_on_identity_component()]
free_id = [P.is_on_identity_component() for P in free]
if any(tor_egg):
Expand Down Expand Up @@ -6207,7 +6207,7 @@ def point_preprocessing(free,tor):
int_points = [P for P in tors_points if not P.is_zero()]
int_points = [P for P in int_points if P[0].is_integral()]
if not both_signs:
xlist = set([P[0] for P in int_points])
xlist = {P[0] for P in int_points}
int_points = [self.lift_x(x) for x in xlist]
int_points.sort()
if verbose:
Expand Down Expand Up @@ -6800,8 +6800,8 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound):
alpha = [(log_ab/R(log(p,e))).floor() for p in S]
if all(alpha_i <= 1 for alpha_i in alpha): # so alpha_i must be 0 to satisfy that denominator is a square
int_abs_bound = abs_bound.floor()
return set(x for x in range(-int_abs_bound, int_abs_bound)
if E.is_x_coord(x))
return {x for x in range(-int_abs_bound, int_abs_bound)
if E.is_x_coord(x)}
else:
xs = []
alpha_max_even = [y - y % 2 for y in alpha]
Expand Down Expand Up @@ -6849,7 +6849,7 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound):
int_points = [P for P in tors_points if not P.is_zero()]
int_points = [P for P in int_points if P[0].is_S_integral(S)]
if not both_signs:
xlist = set([P[0] for P in int_points])
xlist = {P[0] for P in int_points}
int_points = [E.lift_x(x) for x in xlist]
int_points.sort()
if verbose:
Expand Down
1 change: 0 additions & 1 deletion src/sage/schemes/elliptic_curves/ell_tate_curve.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
r"""
Tate's parametrisation of `p`-adic curves with multiplicative reduction
Expand Down
1 change: 0 additions & 1 deletion src/sage/schemes/elliptic_curves/ell_torsion.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
r"""
Torsion subgroups of elliptic curves over number fields (including `\QQ`)
Expand Down
1 change: 0 additions & 1 deletion src/sage/schemes/elliptic_curves/ell_wp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
r"""
Weierstrass `\wp`-function for elliptic curves
Expand Down
1 change: 0 additions & 1 deletion src/sage/schemes/elliptic_curves/formal_group.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
r"""
Formal groups of elliptic curves
Expand Down
1 change: 0 additions & 1 deletion src/sage/schemes/elliptic_curves/gal_reps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
r"""
Galois representations attached to elliptic curves
Expand Down
4 changes: 2 additions & 2 deletions src/sage/schemes/elliptic_curves/gal_reps_number_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ def _semistable_reducible_primes(E, verbose=False):

deg_one_primes = deg_one_primes_iter(K, principal_only=True)

bad_primes = set([]) # This will store the output.
bad_primes = set() # This will store the output.

# We find two primes (of distinct residue characteristics) which are
# of degree 1, unramified in K/Q, and at which E has good reduction.
Expand Down Expand Up @@ -1098,7 +1098,7 @@ def _possible_normalizers(E, SA):

W = W + V.span([splitting_vector])

bad_primes = set([])
bad_primes = set()

for i in traces_list:
for p in i.prime_factors():
Expand Down
Loading

0 comments on commit 4c656cc

Please sign in to comment.