From a5cd3405b8774d0e0b3382f7b772d4759c383f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 12 Dec 2023 21:34:58 +0100 Subject: [PATCH] some ruff auto-fixes in schemes + error links in doc --- src/sage/schemes/affine/affine_space.py | 6 ++--- src/sage/schemes/curves/affine_curve.py | 12 ++++----- src/sage/schemes/curves/projective_curve.py | 6 ++--- src/sage/schemes/curves/zariski_vankampen.py | 8 +++--- .../cyclic_covers/cycliccover_finite_field.py | 4 +-- src/sage/schemes/elliptic_curves/BSD.py | 1 - src/sage/schemes/elliptic_curves/Qcurves.py | 1 - src/sage/schemes/elliptic_curves/cm.py | 2 +- .../schemes/elliptic_curves/ec_database.py | 2 +- .../elliptic_curves/ell_curve_isogeny.py | 3 +-- .../schemes/elliptic_curves/ell_generic.py | 8 +++--- .../schemes/elliptic_curves/ell_local_data.py | 1 - .../elliptic_curves/ell_modular_symbols.py | 1 - .../elliptic_curves/ell_number_field.py | 5 ++-- src/sage/schemes/elliptic_curves/ell_point.py | 1 - .../elliptic_curves/ell_rational_field.py | 22 ++++++++-------- .../schemes/elliptic_curves/ell_tate_curve.py | 1 - .../schemes/elliptic_curves/ell_torsion.py | 1 - src/sage/schemes/elliptic_curves/ell_wp.py | 1 - .../schemes/elliptic_curves/formal_group.py | 1 - src/sage/schemes/elliptic_curves/gal_reps.py | 1 - .../elliptic_curves/gal_reps_number_field.py | 4 +-- src/sage/schemes/elliptic_curves/heegner.py | 6 ++--- .../schemes/elliptic_curves/isogeny_class.py | 16 ++++++------ src/sage/schemes/elliptic_curves/jacobian.py | 1 - src/sage/schemes/elliptic_curves/kraus.py | 1 - .../schemes/elliptic_curves/lseries_ell.py | 1 - src/sage/schemes/elliptic_curves/mod_poly.py | 2 +- .../modular_parametrization.py | 1 - .../schemes/elliptic_curves/saturation.py | 8 +++--- src/sage/schemes/elliptic_curves/sha_tate.py | 3 +-- src/sage/schemes/generic/algebraic_scheme.py | 9 +++---- src/sage/schemes/generic/ambient_space.py | 4 +-- src/sage/schemes/generic/homset.py | 4 +-- src/sage/schemes/generic/scheme.py | 2 +- src/sage/schemes/generic/spec.py | 2 +- .../hyperelliptic_curves/invariants.py | 1 - .../jacobian_endomorphism_utils.py | 1 - .../hyperelliptic_curves/monsky_washnitzer.py | 2 +- .../schemes/jacobians/abstract_jacobian.py | 2 +- src/sage/schemes/plane_conics/con_field.py | 5 ++-- .../con_rational_function_field.py | 1 - src/sage/schemes/plane_conics/constructor.py | 2 +- src/sage/schemes/product_projective/point.py | 4 +-- .../product_projective/rational_point.py | 2 +- src/sage/schemes/product_projective/space.py | 4 +-- .../schemes/projective/proj_bdd_height.py | 26 +++++++++---------- .../schemes/projective/projective_morphism.py | 5 ++-- .../schemes/projective/projective_point.py | 4 +-- .../projective/projective_rational_point.py | 2 +- .../schemes/projective/projective_space.py | 6 ++--- .../riemann_surfaces/riemann_surface.py | 6 ++--- src/sage/schemes/toric/chow_group.py | 3 +-- src/sage/schemes/toric/points.py | 6 ++--- src/sage/schemes/toric/sheaf/constructor.py | 2 +- src/sage/schemes/toric/sheaf/klyachko.py | 2 +- src/sage/schemes/toric/toric_subscheme.py | 14 +++++----- src/sage/schemes/toric/variety.py | 9 +++---- src/sage/schemes/toric/weierstrass.py | 6 ++--- .../schemes/toric/weierstrass_covering.py | 12 ++++----- 60 files changed, 128 insertions(+), 151 deletions(-) diff --git a/src/sage/schemes/affine/affine_space.py b/src/sage/schemes/affine/affine_space.py index ef1ae326a43..fdf38862068 100644 --- a/src/sage/schemes/affine/affine_space.py +++ b/src/sage/schemes/affine/affine_space.py @@ -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): """ @@ -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)]) diff --git a/src/sage/schemes/curves/affine_curve.py b/src/sage/schemes/curves/affine_curve.py index e1032861b2f..d5d97e5e044 100644 --- a/src/sage/schemes/curves/affine_curve.py +++ b/src/sage/schemes/curves/affine_curve.py @@ -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: @@ -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""" @@ -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""" @@ -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): """ @@ -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): """ diff --git a/src/sage/schemes/curves/projective_curve.py b/src/sage/schemes/curves/projective_curve.py index 7c82026b3c1..9480d761f61 100644 --- a/src/sage/schemes/curves/projective_curve.py +++ b/src/sage/schemes/curves/projective_curve.py @@ -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""" @@ -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): @@ -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) diff --git a/src/sage/schemes/curves/zariski_vankampen.py b/src/sage/schemes/curves/zariski_vankampen.py index 0940825b9a5..fa30e97085b 100644 --- a/src/sage/schemes/curves/zariski_vankampen.py +++ b/src/sage/schemes/curves/zariski_vankampen.py @@ -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): @@ -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``. @@ -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) @@ -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] diff --git a/src/sage/schemes/cyclic_covers/cycliccover_finite_field.py b/src/sage/schemes/cyclic_covers/cycliccover_finite_field.py index 82504873715..f2d753baf8f 100644 --- a/src/sage/schemes/cyclic_covers/cycliccover_finite_field.py +++ b/src/sage/schemes/cyclic_covers/cycliccover_finite_field.py @@ -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) @@ -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): diff --git a/src/sage/schemes/elliptic_curves/BSD.py b/src/sage/schemes/elliptic_curves/BSD.py index 85130f0a5f9..bf3f302b978 100644 --- a/src/sage/schemes/elliptic_curves/BSD.py +++ b/src/sage/schemes/elliptic_curves/BSD.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- "Birch and Swinnerton-Dyer formulas" from sage.arith.misc import prime_divisors diff --git a/src/sage/schemes/elliptic_curves/Qcurves.py b/src/sage/schemes/elliptic_curves/Qcurves.py index 45fb5c51293..c7d3da73691 100644 --- a/src/sage/schemes/elliptic_curves/Qcurves.py +++ b/src/sage/schemes/elliptic_curves/Qcurves.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Testing whether elliptic curves over number fields are `\QQ`-curves diff --git a/src/sage/schemes/elliptic_curves/cm.py b/src/sage/schemes/elliptic_curves/cm.py index 03acc69e732..58bed0a67a4 100644 --- a/src/sage/schemes/elliptic_curves/cm.py +++ b/src/sage/schemes/elliptic_curves/cm.py @@ -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 diff --git a/src/sage/schemes/elliptic_curves/ec_database.py b/src/sage/schemes/elliptic_curves/ec_database.py index 043c287ec7e..f66ee2d1d31 100644 --- a/src/sage/schemes/elliptic_curves/ec_database.py +++ b/src/sage/schemes/elliptic_curves/ec_database.py @@ -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) diff --git a/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py b/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py index 59bf8882f1f..fff6dcbefbf 100644 --- a/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py +++ b/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Isogenies @@ -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: diff --git a/src/sage/schemes/elliptic_curves/ell_generic.py b/src/sage/schemes/elliptic_curves/ell_generic.py index 5b569ae54e3..57003863b1b 100644 --- a/src/sage/schemes/elliptic_curves/ell_generic.py +++ b/src/sage/schemes/elliptic_curves/ell_generic.py @@ -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 @@ -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() @@ -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: @@ -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: diff --git a/src/sage/schemes/elliptic_curves/ell_local_data.py b/src/sage/schemes/elliptic_curves/ell_local_data.py index 11a0e9db661..16461506b31 100644 --- a/src/sage/schemes/elliptic_curves/ell_local_data.py +++ b/src/sage/schemes/elliptic_curves/ell_local_data.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Local data for elliptic curves over number fields diff --git a/src/sage/schemes/elliptic_curves/ell_modular_symbols.py b/src/sage/schemes/elliptic_curves/ell_modular_symbols.py index 243df1d23f0..055c7eaec45 100644 --- a/src/sage/schemes/elliptic_curves/ell_modular_symbols.py +++ b/src/sage/schemes/elliptic_curves/ell_modular_symbols.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Modular symbols attached to elliptic curves over `\QQ` diff --git a/src/sage/schemes/elliptic_curves/ell_number_field.py b/src/sage/schemes/elliptic_curves/ell_number_field.py index 8e2993b3375..3f9f5388659 100644 --- a/src/sage/schemes/elliptic_curves/ell_number_field.py +++ b/src/sage/schemes/elliptic_curves/ell_number_field.py @@ -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]) diff --git a/src/sage/schemes/elliptic_curves/ell_point.py b/src/sage/schemes/elliptic_curves/ell_point.py index d35790a13f3..6a6abbc573d 100644 --- a/src/sage/schemes/elliptic_curves/ell_point.py +++ b/src/sage/schemes/elliptic_curves/ell_point.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Points on elliptic curves diff --git a/src/sage/schemes/elliptic_curves/ell_rational_field.py b/src/sage/schemes/elliptic_curves/ell_rational_field.py index 27e52973afd..130eaec9e37 100644 --- a/src/sage/schemes/elliptic_curves/ell_rational_field.py +++ b/src/sage/schemes/elliptic_curves/ell_rational_field.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Elliptic curves over the rational numbers @@ -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] @@ -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): @@ -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): @@ -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: @@ -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] @@ -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: diff --git a/src/sage/schemes/elliptic_curves/ell_tate_curve.py b/src/sage/schemes/elliptic_curves/ell_tate_curve.py index 7b616671e24..6f8d861db93 100644 --- a/src/sage/schemes/elliptic_curves/ell_tate_curve.py +++ b/src/sage/schemes/elliptic_curves/ell_tate_curve.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Tate's parametrisation of `p`-adic curves with multiplicative reduction diff --git a/src/sage/schemes/elliptic_curves/ell_torsion.py b/src/sage/schemes/elliptic_curves/ell_torsion.py index 9a39ead60e5..62b75c79fea 100644 --- a/src/sage/schemes/elliptic_curves/ell_torsion.py +++ b/src/sage/schemes/elliptic_curves/ell_torsion.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Torsion subgroups of elliptic curves over number fields (including `\QQ`) diff --git a/src/sage/schemes/elliptic_curves/ell_wp.py b/src/sage/schemes/elliptic_curves/ell_wp.py index 8785976dec3..b7dd052a701 100644 --- a/src/sage/schemes/elliptic_curves/ell_wp.py +++ b/src/sage/schemes/elliptic_curves/ell_wp.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Weierstrass `\wp`-function for elliptic curves diff --git a/src/sage/schemes/elliptic_curves/formal_group.py b/src/sage/schemes/elliptic_curves/formal_group.py index dbd2db5f778..a7dcb48d36c 100644 --- a/src/sage/schemes/elliptic_curves/formal_group.py +++ b/src/sage/schemes/elliptic_curves/formal_group.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Formal groups of elliptic curves diff --git a/src/sage/schemes/elliptic_curves/gal_reps.py b/src/sage/schemes/elliptic_curves/gal_reps.py index c28b4f76d2c..9543215ee24 100644 --- a/src/sage/schemes/elliptic_curves/gal_reps.py +++ b/src/sage/schemes/elliptic_curves/gal_reps.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Galois representations attached to elliptic curves diff --git a/src/sage/schemes/elliptic_curves/gal_reps_number_field.py b/src/sage/schemes/elliptic_curves/gal_reps_number_field.py index 48f742a6cd0..242aa7ad923 100644 --- a/src/sage/schemes/elliptic_curves/gal_reps_number_field.py +++ b/src/sage/schemes/elliptic_curves/gal_reps_number_field.py @@ -858,7 +858,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. @@ -1096,7 +1096,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(): diff --git a/src/sage/schemes/elliptic_curves/heegner.py b/src/sage/schemes/elliptic_curves/heegner.py index a377c02d5cb..1b5536cc515 100644 --- a/src/sage/schemes/elliptic_curves/heegner.py +++ b/src/sage/schemes/elliptic_curves/heegner.py @@ -844,7 +844,7 @@ def kolyvagin_generators(self): # so we just find a generator. for sigma in self: if sigma.order() == self.cardinality(): - return tuple([sigma]) + return (sigma,) raise NotImplementedError @@ -2568,7 +2568,7 @@ def betas(self): N = self.level() R = Integers(4*N) m = 2*N - return tuple(sorted( set([a % m for a in R(D).sqrt(all=True)]) )) + return tuple(sorted( {a % m for a in R(D).sqrt(all=True)} )) @cached_method def points(self, beta=None): @@ -3776,7 +3776,7 @@ def _square_roots_mod_2N_of_D_mod_4N(self): N = self.__E.conductor() R = Integers(4*N) m = 2*N - return sorted( set([a % m for a in R(self.discriminant()).sqrt(all=True)]) ) + return sorted( {a % m for a in R(self.discriminant()).sqrt(all=True)} ) def _trace_numerical_conductor_1(self, prec=53): """ diff --git a/src/sage/schemes/elliptic_curves/isogeny_class.py b/src/sage/schemes/elliptic_curves/isogeny_class.py index ed05e1760fa..290f2c87d57 100644 --- a/src/sage/schemes/elliptic_curves/isogeny_class.py +++ b/src/sage/schemes/elliptic_curves/isogeny_class.py @@ -410,7 +410,7 @@ def graph(self): M = self.matrix(fill=False) n = len(self) G = Graph(M, format='weighted_adjacency_matrix') - D = dict([(v,self.curves[v]) for v in G.vertices(sort=False)]) + D = {v: self.curves[v] for v in G.vertices(sort=False)} G.set_vertices(D) if self._qfmat: # i.e. self.E.has_rational_cm(): for i in range(n): @@ -424,7 +424,7 @@ def graph(self): n = M.nrows() # = M.ncols() G = Graph(M, format='weighted_adjacency_matrix') N = self.matrix(fill=True) - D = dict([(v,self.curves[v]) for v in G.vertices(sort=False)]) + D = {v: self.curves[v] for v in G.vertices(sort=False)} # The maximum degree classifies the shape of the isogeny # graph, though the number of vertices is often enough. # This only holds over Q, so this code will need to change @@ -876,17 +876,17 @@ def add_tup(t): else: key_function = lambda E: flatten([list(ai) for ai in E.ainvs()]) - self.curves = sorted(curves,key=key_function) - perm = dict([(ind, self.curves.index(Ei)) - for ind, Ei in enumerate(curves)]) + self.curves = sorted(curves, key=key_function) + perm = {ind: self.curves.index(Ei) + for ind, Ei in enumerate(curves)} if verbose: print("Sorting permutation = %s" % perm) mat = MatrixSpace(ZZ, ncurves)(0) self._maps = [[0] * ncurves for _ in range(ncurves)] - for i,j,l,phi in tuples: + for i, j, l, phi in tuples: if phi != 0: - mat[perm[i],perm[j]] = l + mat[perm[i], perm[j]] = l self._maps[perm[i]][perm[j]] = phi self._mat = fill_isogeny_matrix(mat) if verbose: @@ -1109,7 +1109,7 @@ def _compute(self): curves.append(Edash) ijl_triples.append((i,j,l,phi)) if l_list is None: - l_list = [d for d in set([ZZ(f.degree()) for f in isogs])] + l_list = list({ZZ(f.degree()) for f in isogs}) i += 1 self.curves = tuple(curves) ncurves = len(curves) diff --git a/src/sage/schemes/elliptic_curves/jacobian.py b/src/sage/schemes/elliptic_curves/jacobian.py index 1a33c7e4726..23151109453 100644 --- a/src/sage/schemes/elliptic_curves/jacobian.py +++ b/src/sage/schemes/elliptic_curves/jacobian.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Construct elliptic curves as Jacobians diff --git a/src/sage/schemes/elliptic_curves/kraus.py b/src/sage/schemes/elliptic_curves/kraus.py index 8565cc5e3be..92a74f4e718 100644 --- a/src/sage/schemes/elliptic_curves/kraus.py +++ b/src/sage/schemes/elliptic_curves/kraus.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Global and semi-global minimal models for elliptic curves over number fields diff --git a/src/sage/schemes/elliptic_curves/lseries_ell.py b/src/sage/schemes/elliptic_curves/lseries_ell.py index 6e1dfa18c52..f3f1533f7d0 100644 --- a/src/sage/schemes/elliptic_curves/lseries_ell.py +++ b/src/sage/schemes/elliptic_curves/lseries_ell.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ `L`-series for elliptic curves diff --git a/src/sage/schemes/elliptic_curves/mod_poly.py b/src/sage/schemes/elliptic_curves/mod_poly.py index 21926e14c8e..2482bb0da5a 100644 --- a/src/sage/schemes/elliptic_curves/mod_poly.py +++ b/src/sage/schemes/elliptic_curves/mod_poly.py @@ -22,7 +22,7 @@ _db = ClassicalModularPolynomialDatabase() _cache_bound = 100 -_cache = dict() +_cache = {} def classical_modular_polynomial(l, j=None): diff --git a/src/sage/schemes/elliptic_curves/modular_parametrization.py b/src/sage/schemes/elliptic_curves/modular_parametrization.py index 501c17cd571..2ed663e31cb 100644 --- a/src/sage/schemes/elliptic_curves/modular_parametrization.py +++ b/src/sage/schemes/elliptic_curves/modular_parametrization.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Modular parametrization of elliptic curves over `\QQ` diff --git a/src/sage/schemes/elliptic_curves/saturation.py b/src/sage/schemes/elliptic_curves/saturation.py index 095b5b1be12..5e4c66ad78a 100644 --- a/src/sage/schemes/elliptic_curves/saturation.py +++ b/src/sage/schemes/elliptic_curves/saturation.py @@ -128,10 +128,10 @@ def __init__(self, E, verbose=False): else: self._Kpol = K.defining_polynomial() self._D = self._Kpol.discriminant() - self._reductions = dict() - self._lincombs = dict() + self._reductions = {} + self._lincombs = {} self._torsion_gens = [t.element() for t in E.torsion_subgroup().gens()] - self._reductions = dict() + self._reductions = {} # This will hold a dictionary with keys (q,aq) with q prime # and aq a root of K's defining polynomial mod q, and values # (n,gens) where n is the cardinality of the reduction of E @@ -198,7 +198,7 @@ def add_reductions(self, q): """ if q in self._reductions: return - self._reductions[q] = redmodq = dict() + self._reductions[q] = redmodq = {} if q.divides(self._N) or q.divides(self._D): return from sage.schemes.elliptic_curves.constructor import EllipticCurve diff --git a/src/sage/schemes/elliptic_curves/sha_tate.py b/src/sage/schemes/elliptic_curves/sha_tate.py index 33818051b8f..b5a7b48bf0a 100644 --- a/src/sage/schemes/elliptic_curves/sha_tate.py +++ b/src/sage/schemes/elliptic_curves/sha_tate.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Tate-Shafarevich group @@ -1065,7 +1064,7 @@ def bound_kolyvagin(self, D=0, regulator=None, if not ignore_nonsurj_hypothesis: for p in E.galois_representation().non_surjective(): B.append(p) - B = sorted(set(int(x) for x in B)) + B = sorted({int(x) for x in B}) return B, n def bound_kato(self): diff --git a/src/sage/schemes/generic/algebraic_scheme.py b/src/sage/schemes/generic/algebraic_scheme.py index 0648ad2a9f4..2b3c61b5017 100644 --- a/src/sage/schemes/generic/algebraic_scheme.py +++ b/src/sage/schemes/generic/algebraic_scheme.py @@ -371,7 +371,7 @@ def embedding_morphism(self): or neighborhood of a point then the embedding is the embedding into the original scheme. - * A ``NotImplementedError`` is raised if the construction of + * A :class:`NotImplementedError` is raised if the construction of the embedding morphism is not implemented yet. EXAMPLES:: @@ -465,9 +465,8 @@ def embedding_center(self): OUTPUT: - A point of ``self``. Raises ``AttributeError`` if there is no - distinguished point, depending on how ``self`` was - constructed. + A point of ``self``. This raises :class:`AttributeError` if there + is no distinguished point, depending on how ``self`` was constructed. EXAMPLES:: @@ -1133,7 +1132,7 @@ def normalize_defining_polynomials(self): mult = lcm([c.denominator() for c in P.coefficients()]) P = mult*P # stores the common factor from all coefficients - div = gcd([_ for _ in P.coefficients()]) + div = gcd(list(P.coefficients())) poly_ring = P.parent() # need to coerce, since division might change base ring P = poly_ring((BR.one()/div)*P) normalized_polys.append(P) diff --git a/src/sage/schemes/generic/ambient_space.py b/src/sage/schemes/generic/ambient_space.py index d22ea07d149..09d26860af0 100644 --- a/src/sage/schemes/generic/ambient_space.py +++ b/src/sage/schemes/generic/ambient_space.py @@ -219,8 +219,8 @@ def base_extend(self, R): .. NOTE:: - A ``ValueError`` is raised if there is no such natural map. If - you need to drop this condition, use ``self.change_ring(R)``. + A :class:`ValueError` is raised if there is no such natural map. + If you need to drop this condition, use ``self.change_ring(R)``. EXAMPLES:: diff --git a/src/sage/schemes/generic/homset.py b/src/sage/schemes/generic/homset.py index 60e840619ac..a9a0f0735df 100644 --- a/src/sage/schemes/generic/homset.py +++ b/src/sage/schemes/generic/homset.py @@ -175,7 +175,7 @@ def create_key_and_extra_args(self, X, Y, category=None, base=None, if not category: from sage.categories.schemes import Schemes category = Schemes(base_spec) - key = tuple([id(X), id(Y), category, as_point_homset]) + key = (id(X), id(Y), category, as_point_homset) extra = {'X':X, 'Y':Y, 'base_ring':base_ring, 'check':check} return key, extra @@ -313,7 +313,7 @@ def natural_map(self): OUTPUT: A :class:`SchemeMorphism` if there is a natural map from - domain to codomain. Otherwise, a ``NotImplementedError`` is + domain to codomain. Otherwise, a :class:`NotImplementedError` is raised. EXAMPLES:: diff --git a/src/sage/schemes/generic/scheme.py b/src/sage/schemes/generic/scheme.py index da188ac63b3..88e7e6a61c2 100644 --- a/src/sage/schemes/generic/scheme.py +++ b/src/sage/schemes/generic/scheme.py @@ -498,7 +498,7 @@ def coordinate_ring(self): OUTPUT: The global coordinate ring of this scheme, if - defined. Otherwise raise a ``ValueError``. + defined. Otherwise this raises a :class:`ValueError`. EXAMPLES:: diff --git a/src/sage/schemes/generic/spec.py b/src/sage/schemes/generic/spec.py index c9a07313bb3..92453a86bf4 100644 --- a/src/sage/schemes/generic/spec.py +++ b/src/sage/schemes/generic/spec.py @@ -54,7 +54,7 @@ def Spec(R, S=None): sage: A is B True - A ``TypeError`` is raised if the input is not a commutative ring:: + A :class:`TypeError` is raised if the input is not a commutative ring:: sage: Spec(5) Traceback (most recent call last): diff --git a/src/sage/schemes/hyperelliptic_curves/invariants.py b/src/sage/schemes/hyperelliptic_curves/invariants.py index 05bffb5c113..a0101f60a3c 100644 --- a/src/sage/schemes/hyperelliptic_curves/invariants.py +++ b/src/sage/schemes/hyperelliptic_curves/invariants.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Compute invariants of quintics and sextics via 'Ueberschiebung' diff --git a/src/sage/schemes/hyperelliptic_curves/jacobian_endomorphism_utils.py b/src/sage/schemes/hyperelliptic_curves/jacobian_endomorphism_utils.py index 8d8d89896db..2ceb709b646 100644 --- a/src/sage/schemes/hyperelliptic_curves/jacobian_endomorphism_utils.py +++ b/src/sage/schemes/hyperelliptic_curves/jacobian_endomorphism_utils.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Some functions regarding geometric endomorphism rings of Jacobians of hyperelliptic curves. diff --git a/src/sage/schemes/hyperelliptic_curves/monsky_washnitzer.py b/src/sage/schemes/hyperelliptic_curves/monsky_washnitzer.py index f8c8f847350..fb3b8bd8d4b 100644 --- a/src/sage/schemes/hyperelliptic_curves/monsky_washnitzer.py +++ b/src/sage/schemes/hyperelliptic_curves/monsky_washnitzer.py @@ -1683,7 +1683,7 @@ def matrix_of_frobenius(Q, p, M, trace=None, compute_exact_forms=False): F1_coeffs = transpose_list(F1.coeffs()) F1_modp_coeffs = F1_coeffs[int((M-2)*p):] # make a copy, because reduce_all will destroy the coefficients: - F1_modp_coeffs = [[cell for cell in row] for row in F1_modp_coeffs] + F1_modp_coeffs = [list(row) for row in F1_modp_coeffs] F1_modp_offset = offset - (M-2)*p F1_modp_reduced = reduce_all(Q, p, F1_modp_coeffs, F1_modp_offset) diff --git a/src/sage/schemes/jacobians/abstract_jacobian.py b/src/sage/schemes/jacobians/abstract_jacobian.py index 8fece57a242..9ab2ef283ae 100644 --- a/src/sage/schemes/jacobians/abstract_jacobian.py +++ b/src/sage/schemes/jacobians/abstract_jacobian.py @@ -177,7 +177,7 @@ def _point(self): OUTPUT: - This method always raises a ``NotImplementedError``; it is + This method always raises a :class:`NotImplementedError`; it is only abstract. EXAMPLES:: diff --git a/src/sage/schemes/plane_conics/con_field.py b/src/sage/schemes/plane_conics/con_field.py index 97bd54408ac..26bea07db90 100644 --- a/src/sage/schemes/plane_conics/con_field.py +++ b/src/sage/schemes/plane_conics/con_field.py @@ -1050,7 +1050,7 @@ def rational_point(self, algorithm='default', read_cache=True): r""" Return a point on ``self`` defined over the base field. - Raises ``ValueError`` if no rational point exists. + This raises a :class:`ValueError` if no rational point exists. See ``self.has_rational_point`` for the algorithm used and for the use of the parameters ``algorithm`` and ``read_cache``. @@ -1202,7 +1202,8 @@ def singular_point(self): sage: Conic(GF(2), [1,1,1,1,1,1]).singular_point() (1 : 1 : 1) - ``ValueError`` is raised if the conic has no rational singular point + :class:`ValueError` is raised if the conic has no rational + singular point :: diff --git a/src/sage/schemes/plane_conics/con_rational_function_field.py b/src/sage/schemes/plane_conics/con_rational_function_field.py index 581102b5c5b..a5dcfb9bf1b 100644 --- a/src/sage/schemes/plane_conics/con_rational_function_field.py +++ b/src/sage/schemes/plane_conics/con_rational_function_field.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Projective plane conics over a rational function field diff --git a/src/sage/schemes/plane_conics/constructor.py b/src/sage/schemes/plane_conics/constructor.py index 20bc5630ac1..7bb681a4268 100644 --- a/src/sage/schemes/plane_conics/constructor.py +++ b/src/sage/schemes/plane_conics/constructor.py @@ -92,7 +92,7 @@ def Conic(base_field, F=None, names=None, unique=True): - ``unique`` -- Used only if ``F`` is a list of points in the plane. If the conic through the points is not unique, then - raise ``ValueError`` if and only if ``unique`` is True + raise :class:`ValueError` if and only if ``unique`` is ``True`` OUTPUT: diff --git a/src/sage/schemes/product_projective/point.py b/src/sage/schemes/product_projective/point.py index 70cc344806f..6de7cf74d7d 100644 --- a/src/sage/schemes/product_projective/point.py +++ b/src/sage/schemes/product_projective/point.py @@ -368,8 +368,8 @@ def scale_by(self, t): r""" Scale the coordinates of the point by ``t``, done componentwise. - A ``TypeError`` occurs if the point is not in the base ring of the - codomain after scaling. + A :class:`TypeError` occurs if the point is not in the base ring + of the codomain after scaling. INPUT: diff --git a/src/sage/schemes/product_projective/rational_point.py b/src/sage/schemes/product_projective/rational_point.py index c9a2cf6b25f..a4488647063 100644 --- a/src/sage/schemes/product_projective/rational_point.py +++ b/src/sage/schemes/product_projective/rational_point.py @@ -393,7 +393,7 @@ def good_primes(B): of the ambient space. """ - M = dict() # stores optimal list of primes, corresponding to list size + M = {} # stores optimal list of primes, corresponding to list size small_primes = sufficient_primes(B) max_length = len(small_primes) M[max_length] = small_primes diff --git a/src/sage/schemes/product_projective/space.py b/src/sage/schemes/product_projective/space.py index 0293e666cd6..3fee46cc15a 100644 --- a/src/sage/schemes/product_projective/space.py +++ b/src/sage/schemes/product_projective/space.py @@ -624,7 +624,7 @@ def _degree(self, polynomial): - ``polynomial`` -- a polynomial in the coordinate_ring OUTPUT: A tuple of integers, one for each projective space component. A - ``ValueError`` is raised if the polynomial is not multihomogeneous. + :class:`ValueError` is raised if the polynomial is not multihomogeneous. EXAMPLES:: @@ -694,7 +694,7 @@ def _point_homset(self, *args, **kwds): def _validate(self, polynomials): r""" If ``polynomials`` is a tuple of valid polynomial functions on this space, - return ``polynomials``, otherwise raise a ``TypeError``. + return ``polynomials``, otherwise raise a :class:`TypeError`. Since this is a product of projective spaces, the polynomials must be multi-homogeneous. diff --git a/src/sage/schemes/projective/proj_bdd_height.py b/src/sage/schemes/projective/proj_bdd_height.py index 744313fc77f..86100cf832a 100644 --- a/src/sage/schemes/projective/proj_bdd_height.py +++ b/src/sage/schemes/projective/proj_bdd_height.py @@ -78,9 +78,9 @@ def ZZ_points_of_bounded_height(PS, dim, bound): [] """ if bound < 1: - return iter(set([])) + return iter(set()) - points_of_bounded_height = set([]) + points_of_bounded_height = set() for t in itertools.product(range(-bound, bound+1), repeat=dim+1): if gcd(t) == 1: @@ -133,10 +133,10 @@ def QQ_points_of_bounded_height(PS, dim, bound, normalize=False): [] """ if bound < 1: - return iter(set([])) + return iter(set()) unit_tuples = list(itertools.product([-1, 1], repeat=dim)) - points_of_bounded_height = set([]) + points_of_bounded_height = set() increasing_tuples = itertools.combinations_with_replacement(range(floor(bound + 1)), dim + 1) for t in increasing_tuples: if gcd(t) == 1: @@ -190,12 +190,12 @@ def IQ_points_of_bounded_height(PS, K, dim, bound): class_group_ideal_norms = [i.norm() for i in class_group_ideals] class_number = len(class_group_ideals) - possible_norm_set = set([]) + possible_norm_set = set() for i in range(class_number): for k in range(1, floor(bound + 1)): possible_norm_set.add(k*class_group_ideal_norms[i]) - coordinate_space = dict() + coordinate_space = {} coordinate_space[0] = [K(0)] for m in possible_norm_set: coordinate_space[m] = K.elements_of_norm(m) @@ -212,7 +212,7 @@ def IQ_points_of_bounded_height(PS, K, dim, bound): if x in a: a_coordinates.append(x) - points_in_class_a = set([]) + points_in_class_a = set() t = len(a_coordinates) - 1 increasing_tuples = itertools.combinations_with_replacement(range(t + 1), dim + 1) for index_tuple in increasing_tuples: @@ -345,12 +345,12 @@ def points_of_bounded_height(PS, K, dim, bound, prec=53): fundamental_units = lll_fund_units fund_unit_logs = list(map(log_embed, fundamental_units)) - possible_norm_set = set([]) + possible_norm_set = set() for i in range(class_number): for k in range(1, floor(bound + 1)): possible_norm_set.add(k*class_group_ideal_norms[i]) - principal_ideal_gens = dict() + principal_ideal_gens = {} negative_norm_units = K.elements_of_norm(-1) if len(negative_norm_units) == 0: for m in possible_norm_set: @@ -359,7 +359,7 @@ def points_of_bounded_height(PS, K, dim, bound, prec=53): for m in possible_norm_set: principal_ideal_gens[m] = K.elements_of_norm(m) - pr_ideal_gen_logs = dict() + pr_ideal_gen_logs = {} for key in principal_ideal_gens: for y in principal_ideal_gens[key]: pr_ideal_gen_logs[y] = log_embed(y) @@ -398,11 +398,11 @@ def points_of_bounded_height(PS, K, dim, bound, prec=53): T_it = T.inverse().transpose() unit_polytope = Polyhedron([v*T_it for v in vertices]) - coordinate_space = dict() + coordinate_space = {} coordinate_space[0] = [[K(0), log_embed(0)]] int_points = unit_polytope.integral_points() - units_with_logs = dict() + units_with_logs = {} for n in int_points: new_unit = 1 for j in range(r): @@ -444,7 +444,7 @@ def points_of_bounded_height(PS, K, dim, bound, prec=53): a_coordinates.append(pair) t = len(a_coordinates) - 1 - points_in_class_a = set([]) + points_in_class_a = set() increasing_tuples = itertools.combinations_with_replacement(range(t + 1), dim + 1) log_arch_height_bound = logB + log_a_norm for index_tuple in increasing_tuples: diff --git a/src/sage/schemes/projective/projective_morphism.py b/src/sage/schemes/projective/projective_morphism.py index 2983b03796e..fe408bd1d42 100644 --- a/src/sage/schemes/projective/projective_morphism.py +++ b/src/sage/schemes/projective/projective_morphism.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Morphisms on projective schemes @@ -735,9 +734,9 @@ def as_dynamical_system(self): def scale_by(self, t): """ - Scales each coordinate by a factor of ``t``. + Scale each coordinate by a factor of ``t``. - A ``TypeError`` occurs if the point is not in the coordinate ring + A :class:`TypeError` occurs if the point is not in the coordinate ring of the parent after scaling. INPUT: diff --git a/src/sage/schemes/projective/projective_point.py b/src/sage/schemes/projective/projective_point.py index e22e0a858b1..55bd5354976 100644 --- a/src/sage/schemes/projective/projective_point.py +++ b/src/sage/schemes/projective/projective_point.py @@ -488,11 +488,11 @@ def _matrix_times_point_(self, mat, dom): X = mat * vector(list(self)) return dom.codomain()(list(X)) - def scale_by(self,t): + def scale_by(self, t): """ Scale the coordinates of the point by ``t``. - A ``TypeError`` occurs if the point is not in the + A :class:`TypeError` occurs if the point is not in the base_ring of the codomain after scaling. INPUT: diff --git a/src/sage/schemes/projective/projective_rational_point.py b/src/sage/schemes/projective/projective_rational_point.py index cc99ba389ac..6e08612f88b 100644 --- a/src/sage/schemes/projective/projective_rational_point.py +++ b/src/sage/schemes/projective/projective_rational_point.py @@ -412,7 +412,7 @@ def good_primes(B): where alpha is product of all primes, and P_max is largest prime in list. """ - M = dict() # stores optimal list of primes, corresponding to list size + M = {} # stores optimal list of primes, corresponding to list size small_primes = sufficient_primes(B) max_length = len(small_primes) M[max_length] = small_primes diff --git a/src/sage/schemes/projective/projective_space.py b/src/sage/schemes/projective/projective_space.py index c1402654a87..aa2b5357280 100644 --- a/src/sage/schemes/projective/projective_space.py +++ b/src/sage/schemes/projective/projective_space.py @@ -1951,7 +1951,7 @@ def hyperplane_transformation_matrix(self, plane_1, plane_2): base_list = [list(s) for s in source_points] elif len(source_points) == N + 1: Ms = matrix(base_list + [point.change_ring(self.base_ring())]) - if not any([m == 0 for m in Ms.minors(N + 1)]): + if not any(m == 0 for m in Ms.minors(N + 1)): source_points.append(self(point)) break if len(source_points) != N+2: @@ -2371,10 +2371,10 @@ def rational_points(self, F=None): (b + 1 : 1), (b + 2 : 1), (b : 1)] """ if F is None: - 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 rational_points_dictionary(self): r""" diff --git a/src/sage/schemes/riemann_surfaces/riemann_surface.py b/src/sage/schemes/riemann_surfaces/riemann_surface.py index b7e3f1ac8f6..a7760fa7101 100644 --- a/src/sage/schemes/riemann_surfaces/riemann_surface.py +++ b/src/sage/schemes/riemann_surfaces/riemann_surface.py @@ -1688,10 +1688,10 @@ def direction(center, neighbour): # that entry, and the corresponding cycle. (also, forms it # into a loop) if P[i][j] != 0: - acycles[i] += [(P[i][j], [x for x in cycles[j]] + [cycles[j][0]])] + acycles[i] += [(P[i][j], list(cycles[j]) + [cycles[j][0]])] if P[self.genus + i][j] != 0: bcycles[i] += [ - (P[self.genus + i][j], [x for x in cycles[j]] + [cycles[j][0]]) + (P[self.genus + i][j], list(cycles[j]) + [cycles[j][0]]) ] return acycles + bcycles @@ -2326,7 +2326,7 @@ def normalize_pairs(L): integral_dict = self._integral_dict else: fcd = [fast_callable(omega, domain=self._CC) for omega in differentials] - integral_dict = dict() + integral_dict = {} if integration_method == "heuristic": line_int = lambda edge: self.simple_vector_line_integral(edge, fcd) diff --git a/src/sage/schemes/toric/chow_group.py b/src/sage/schemes/toric/chow_group.py index dac091a4f6f..9b612ece0eb 100644 --- a/src/sage/schemes/toric/chow_group.py +++ b/src/sage/schemes/toric/chow_group.py @@ -1,5 +1,4 @@ # sage.doctest: needs sage.geometry.polyhedron sage.graphs -# -*- coding: utf-8 -*- r""" The Chow group of a toric variety @@ -553,7 +552,7 @@ def create_key_and_extra_args(self, toric_variety, base_ring=ZZ, check=True): if base_ring not in [ZZ, QQ]: raise ValueError('base ring must be either ZZ or QQ') - key = tuple([toric_variety, base_ring]) + key = (toric_variety, base_ring) extra = {'check': check} return key, extra diff --git a/src/sage/schemes/toric/points.py b/src/sage/schemes/toric/points.py index 4a40aa82ef7..20507e5c0af 100644 --- a/src/sage/schemes/toric/points.py +++ b/src/sage/schemes/toric/points.py @@ -96,7 +96,7 @@ def __iter__(self): rays = self.fan().rays() + self.fan().virtual_rays() n = len(rays) if n == 0: - yield tuple() + yield () else: R = self.ring p = [R.one() for k in range(n)] @@ -242,7 +242,7 @@ def _Chow_group_torsion(self): ((1, 2, 4), (1, 4, 2)) """ if self.fan.is_smooth(): - return tuple() + return () image = self.rays().column_matrix().image() torsion = image.saturation().quotient(image) result = set() @@ -539,7 +539,7 @@ def _Chow_group_torsion_generators(self): ((1, 2, 4),) """ if self.fan.is_smooth(): - return tuple() + return () image = self.rays().column_matrix().image() torsion = image.saturation().quotient(image) result = set() diff --git a/src/sage/schemes/toric/sheaf/constructor.py b/src/sage/schemes/toric/sheaf/constructor.py index 52f00d99815..72ed52a0115 100644 --- a/src/sage/schemes/toric/sheaf/constructor.py +++ b/src/sage/schemes/toric/sheaf/constructor.py @@ -40,7 +40,7 @@ def TangentBundle(X): raise ValueError('not a toric variety') fan = X.fan() - filtrations = dict() + filtrations = {} from sage.modules.filtered_vector_space import FilteredVectorSpace for i, ray in enumerate(fan.rays()): F = FilteredVectorSpace(fan.rays(), {0: range(fan.nrays()), 1: [i]}) diff --git a/src/sage/schemes/toric/sheaf/klyachko.py b/src/sage/schemes/toric/sheaf/klyachko.py index 08cea1487f9..4325e77f186 100644 --- a/src/sage/schemes/toric/sheaf/klyachko.py +++ b/src/sage/schemes/toric/sheaf/klyachko.py @@ -685,7 +685,7 @@ def cohomology(self, degree=None, weight=None, dim=False): C = self.cohomology_complex(weight) space_dim = self._variety.dimension() C_homology = C.homology() - HH = dict() + HH = {} for d in range(space_dim+1): try: HH[d] = C_homology[d] diff --git a/src/sage/schemes/toric/toric_subscheme.py b/src/sage/schemes/toric/toric_subscheme.py index 6b3645d0e4a..c4e1785b400 100644 --- a/src/sage/schemes/toric/toric_subscheme.py +++ b/src/sage/schemes/toric/toric_subscheme.py @@ -220,7 +220,7 @@ def affine_patch(self, i): try: return self._affine_patches[i] except AttributeError: - self._affine_patches = dict() + self._affine_patches = {} except KeyError: pass ambient_patch = self.ambient_space().affine_patch(i) @@ -315,9 +315,9 @@ def affine_algebraic_patch(self, cone=None, names=None): R, I, dualcone = ambient._semigroup_ring(cone, names) # inhomogenize the Cox homogeneous polynomial with respect to the given cone - inhomogenize = dict( (ambient.coordinate_ring().gen(i), 1) - for i in range(0,fan.nrays()) - if i not in cone.ambient_ray_indices() ) + inhomogenize = {ambient.coordinate_ring().gen(i): 1 + for i in range(fan.nrays()) + if i not in cone.ambient_ray_indices()} polynomials = [p.subs(inhomogenize) for p in self.defining_polynomials()] # map the monomial x^{D_m} to m, see reference. @@ -402,7 +402,7 @@ def _best_affine_patch(self, point): # that it is numerically stable to dehomogenize, see the # corresponding method for projective varieties. point = list(point) - zeros = set(i for i, coord in enumerate(point) if coord == 0) + zeros = {i for i, coord in enumerate(point) if coord == 0} for cone_idx, cone in enumerate(self.ambient_space().fan().generating_cones()): if zeros.issubset(cone.ambient_ray_indices()): return cone_idx @@ -677,8 +677,8 @@ def is_nondegenerate(self): SR = SR.change_ring(R) def restrict(cone): - patch = dict() - divide = dict() + patch = {} + divide = {} for i in cone.ambient_ray_indices(): patch[R.gen(i)] = R.zero() # restrict to torus orbit # divide out highest power of R.gen(i) diff --git a/src/sage/schemes/toric/variety.py b/src/sage/schemes/toric/variety.py index 3635e7abbd4..9b06bd0223c 100644 --- a/src/sage/schemes/toric/variety.py +++ b/src/sage/schemes/toric/variety.py @@ -1,5 +1,4 @@ # sage.doctest: needs sage.geometry.polyhedron sage.graphs -# -*- coding: utf-8 -*- r""" Toric varieties @@ -709,9 +708,9 @@ def _check_satisfies_equations(self, coordinates): if coordinate not in base_field: raise TypeError("coordinate %s is not an element of %s" % (coordinate, base_field)) - zero_positions = set(position - for position, coordinate in enumerate(coordinates) - if coordinate == 0) + zero_positions = {position + for position, coordinate in enumerate(coordinates) + if coordinate == 0} if not zero_positions: return True for i in range(n - self._torus_factor_dim, n): @@ -2731,7 +2730,7 @@ def orbit_closure(self, cone): star_rays = set() for star_cone in cone.star_generators(): star_rays.update(star_cone.rays()) - ray_map = dict( (ray, self._orbit_closure_projection(cone, ray)) for ray in star_rays) + ray_map = {ray: self._orbit_closure_projection(cone, ray) for ray in star_rays} from sage.schemes.toric.morphism import SchemeMorphism_orbit_closure_toric_variety orbit_closure._embedding_morphism = \ SchemeMorphism_orbit_closure_toric_variety(orbit_closure.Hom(self), cone, ray_map) diff --git a/src/sage/schemes/toric/weierstrass.py b/src/sage/schemes/toric/weierstrass.py index 137dfd3e042..b727e586141 100644 --- a/src/sage/schemes/toric/weierstrass.py +++ b/src/sage/schemes/toric/weierstrass.py @@ -281,7 +281,7 @@ def Newton_polytope_vars_coeffs(polynomial, variables): """ R = polynomial.parent() var_indices = [R.gens().index(x) for x in variables] - result = dict() + result = {} for c, m in polynomial: e = m.exponents()[0] v = tuple([e[i] for i in var_indices]) @@ -596,7 +596,7 @@ def index(monomial): return tuple(0 for i in indices) e = monomial.exponents()[0] return tuple(e[i] for i in indices) - coeffs = dict() + coeffs = {} for c, m in polynomial: i = index(m) coeffs[i] = c*m + coeffs.pop(i, R.zero()) @@ -992,7 +992,7 @@ def _check_polynomial_P2_112(polynomial, variables): _check_homogeneity(polynomial, variables, (1, 0, 1, -2), 0) _check_homogeneity(polynomial, variables, (0, 1, 0, 1), 2) elif len(variables) == 2: - variables = tuple([variables[0], variables[1], None, None]) + variables = (variables[0], variables[1], None, None) else: raise ValueError(f'need two or four variables, got {variables}') return variables diff --git a/src/sage/schemes/toric/weierstrass_covering.py b/src/sage/schemes/toric/weierstrass_covering.py index cc9caeeae4d..128c30d33a8 100644 --- a/src/sage/schemes/toric/weierstrass_covering.py +++ b/src/sage/schemes/toric/weierstrass_covering.py @@ -255,9 +255,9 @@ def homogenize(inhomog, degree): result = vector(ZZ, result) result.set_immutable() return result - X_dict = dict((homogenize(e, 2), v) for e, v in X.dict().items()) - Y_dict = dict((homogenize(e, 3), v) for e, v in Y.dict().items()) - Z_dict = dict((homogenize(e, 1), v) for e, v in Z.dict().items()) + X_dict = {homogenize(e, 2): v for e, v in X.dict().items()} + Y_dict = {homogenize(e, 3): v for e, v in Y.dict().items()} + Z_dict = {homogenize(e, 1): v for e, v in Z.dict().items()} # shift to non-negative exponents if necessary min_deg = [0] * R.ngens() for var in variables: @@ -267,9 +267,9 @@ def homogenize(inhomog, degree): min_Z = min([e[i] for e in Z_dict]) if Z_dict else 0 min_deg[i] = min(min_X / 2, min_Y / 3, min_Z) min_deg = vector(min_deg) - X_dict = dict((tuple(e - 2 * min_deg), v) for e, v in X_dict.items()) - Y_dict = dict((tuple(e - 3 * min_deg), v) for e, v in Y_dict.items()) - Z_dict = dict((tuple(e - 1 * min_deg), v) for e, v in Z_dict.items()) + X_dict = {tuple(e - 2 * min_deg): v for e, v in X_dict.items()} + Y_dict = {tuple(e - 3 * min_deg): v for e, v in Y_dict.items()} + Z_dict = {tuple(e - 1 * min_deg): v for e, v in Z_dict.items()} return (R(X_dict), R(Y_dict), R(Z_dict))