From 552a84be4b10d737b83ab212333eff4edfb3588c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sun, 29 Sep 2024 13:26:48 +0200 Subject: [PATCH 1/2] fixing some suggestions by ruff --- .../commutative_additive_semigroups.py | 10 +++--- src/sage/categories/pushout.py | 8 ++--- src/sage/coding/code_bounds.py | 2 +- src/sage/coding/source_coding/huffman.py | 2 +- src/sage/combinat/interval_posets.py | 3 +- .../combinat/root_system/type_reducible.py | 2 +- src/sage/combinat/sf/sfa.py | 2 +- src/sage/crypto/mq/rijndael_gf.py | 32 +++++++++---------- src/sage/data_structures/stream.py | 4 +-- src/sage/databases/cremona.py | 6 ++-- src/sage/databases/findstat.py | 2 +- src/sage/databases/sql_db.py | 6 ++-- src/sage/doctest/control.py | 2 +- src/sage/doctest/external.py | 2 +- src/sage/doctest/fixtures.py | 4 +-- src/sage/doctest/forker.py | 2 +- src/sage/doctest/parsing.py | 2 +- src/sage/doctest/sources.py | 2 +- .../arithmetic_dynamics/berkovich_ds.py | 2 +- src/sage/dynamics/cellular_automata/glca.py | 18 +++++------ .../dynamics/complex_dynamics/mandel_julia.py | 1 + src/sage/env.py | 2 +- src/sage/features/__init__.py | 2 +- src/sage/functions/hypergeometric.py | 6 ++-- src/sage/functions/piecewise.py | 2 +- src/sage/game_theory/matching_game.py | 2 +- src/sage/game_theory/normal_form_game.py | 2 +- src/sage/game_theory/parser.py | 2 +- src/sage/games/sudoku.py | 6 ++-- src/sage/geometry/fan.py | 4 +-- src/sage/geometry/hasse_diagram.py | 4 +-- src/sage/groups/finitely_presented.py | 2 +- src/sage/homology/chain_complex.py | 26 +++++++-------- src/sage/homology/chains.py | 2 +- src/sage/interfaces/expect.py | 2 +- src/sage/interfaces/four_ti_2.py | 2 +- src/sage/interfaces/gfan.py | 2 +- src/sage/interfaces/interface.py | 9 ++++-- src/sage/interfaces/maxima_lib.py | 6 ++-- src/sage/interfaces/sympy.py | 4 +-- src/sage/interfaces/tab_completion.py | 2 +- src/sage/knots/knot.py | 24 +++++++------- src/sage/lfunctions/pari.py | 2 +- src/sage/libs/gap/context_managers.py | 2 +- src/sage/libs/singular/function_factory.py | 2 +- src/sage/modular/abvar/abvar.py | 4 +-- src/sage/modular/abvar/torsion_subgroup.py | 4 +-- src/sage/modular/arithgroup/tests.py | 2 +- src/sage/modular/btquotients/btquotient.py | 4 +-- .../modular/btquotients/pautomorphicform.py | 4 +-- src/sage/modular/drinfeld_modform/ring.py | 4 +-- src/sage/modular/pollack_stevens/manin_map.py | 2 +- src/sage/parallel/decorate.py | 6 ++-- src/sage/parallel/map_reduce.py | 6 ++-- src/sage/parallel/use_fork.py | 4 +-- src/sage/plot/streamline_plot.py | 5 ++- src/sage/quivers/path_semigroup.py | 2 +- src/sage/repl/configuration.py | 2 +- src/sage/repl/display/fancy_repr.py | 2 +- src/sage/repl/display/util.py | 2 +- src/sage/repl/interface_magic.py | 2 +- src/sage/repl/interpreter.py | 2 +- src/sage/repl/ipython_extension.py | 2 +- src/sage/repl/ipython_kernel/install.py | 2 +- src/sage/repl/ipython_kernel/widgets.py | 4 +-- src/sage/repl/rich_output/display_manager.py | 2 +- src/sage/repl/rich_output/output_basic.py | 6 ++-- ...otics_multivariate_generating_functions.py | 2 +- src/sage/rings/continued_fraction_gosper.py | 2 +- src/sage/rings/invariants/invariant_theory.py | 2 +- src/sage/rings/lazy_series.py | 4 +-- .../rings/multi_power_series_ring_element.py | 2 +- .../small_primes_of_degree_one.py | 2 +- src/sage/rings/padics/lattice_precision.py | 2 +- .../polynomial/multi_polynomial_element.py | 2 +- .../polynomial_quotient_ring_element.py | 2 +- src/sage/rings/valuation/valuation.py | 2 +- src/sage/sat/converters/anf2cnf.py | 2 +- src/sage/sat/converters/polybori.py | 2 +- src/sage/schemes/toric/fano_variety.py | 10 +++--- src/sage/sets/integer_range.py | 2 +- src/sage/sets/set.py | 2 +- src/sage/sets/set_from_iterator.py | 4 +-- src/sage/structure/global_options.py | 2 +- src/sage/structure/indexed_generators.py | 2 +- src/sage/structure/proof/proof.py | 2 +- src/sage/structure/test_factory.py | 2 +- src/sage/symbolic/constants.py | 2 +- src/sage/symbolic/function_factory.py | 2 +- src/sage/symbolic/operators.py | 6 ++-- .../tensor/modules/finite_rank_free_module.py | 2 +- .../tensor/modules/free_module_element.py | 4 +-- .../topology/simplicial_complex_morphism.py | 17 ++++------ src/sage/typeset/character_art.py | 2 +- 94 files changed, 191 insertions(+), 202 deletions(-) diff --git a/src/sage/categories/examples/commutative_additive_semigroups.py b/src/sage/categories/examples/commutative_additive_semigroups.py index 78f0eedb2d0..78701a16be3 100644 --- a/src/sage/categories/examples/commutative_additive_semigroups.py +++ b/src/sage/categories/examples/commutative_additive_semigroups.py @@ -166,11 +166,10 @@ def __init__(self, parent, iterable): {'a': 2, 'b': 0, 'c': 1, 'd': 5} """ d = {a: 0 for a in parent.alphabet} - for a, c in iterable: - d[a] = c + d.update(iterable) ElementWrapper.__init__(self, parent, d) - def _repr_(self): + def _repr_(self) -> str: """ EXAMPLES:: @@ -182,8 +181,9 @@ def _repr_(self): 0 """ d = self.value - result = ' + '.join( ("%s*%s" % (d[a],a) if d[a] != 1 else a) for a in sorted(d.keys()) if d[a] != 0) - return '0' if result == '' else result + result = ' + '.join(("%s*%s" % (d[a], a) if d[a] != 1 else a) + for a in sorted(d.keys()) if d[a] != 0) + return '0' if not result else result def __hash__(self): """ diff --git a/src/sage/categories/pushout.py b/src/sage/categories/pushout.py index e3d2d3f796d..b67f37ed524 100644 --- a/src/sage/categories/pushout.py +++ b/src/sage/categories/pushout.py @@ -3055,13 +3055,11 @@ def merge(self, other): codomain = self.codomain().join([self.codomain(), other.codomain()]) # Get the optional arguments: as_field = self.as_field or other.as_field - kwds = {} - for k,v in self.kwds.items(): - kwds[k] = v - for k,v in other.kwds.items(): + kwds = dict(self.kwds) + for k, v in other.kwds.items(): if k == 'category': if kwds[k] is not None: - kwds[k] = v.join([v,kwds[k]]) + kwds[k] = v.join([v, kwds[k]]) else: kwds[k] = v continue diff --git a/src/sage/coding/code_bounds.py b/src/sage/coding/code_bounds.py index 99400522265..4bb33d9565f 100644 --- a/src/sage/coding/code_bounds.py +++ b/src/sage/coding/code_bounds.py @@ -737,7 +737,7 @@ def elias_bound_asymp(delta, q): 0.39912396330... """ r = 1 - 1 / q - return RDF((1-entropy(r-sqrt(r*(r-delta)), q))) + return RDF(1-entropy(r-sqrt(r*(r-delta)), q)) def mrrw1_bound_asymp(delta, q): diff --git a/src/sage/coding/source_coding/huffman.py b/src/sage/coding/source_coding/huffman.py index df4e0b96eff..2755e033632 100644 --- a/src/sage/coding/source_coding/huffman.py +++ b/src/sage/coding/source_coding/huffman.py @@ -394,7 +394,7 @@ def encode(self, string): 'Sage is my most favorite general purpose computer algebra system' """ if self._character_to_code: - return "".join((self._character_to_code[x] for x in string)) + return "".join(self._character_to_code[x] for x in string) def decode(self, string): r""" diff --git a/src/sage/combinat/interval_posets.py b/src/sage/combinat/interval_posets.py index 24084d03b82..046d2ba3a7f 100644 --- a/src/sage/combinat/interval_posets.py +++ b/src/sage/combinat/interval_posets.py @@ -3533,8 +3533,7 @@ def profil(gr, vertex): liste = clockwise_labelling(graph0, -1)[1:] relabelling = {l: i for i, l in enumerate(liste)} - for l in [-1, -2, -3]: - relabelling[l] = l + relabelling.update((i, i) for i in [-1, -2, -3]) new_graph = graph.relabel(relabelling, inplace=False) dyckword_top = [] diff --git a/src/sage/combinat/root_system/type_reducible.py b/src/sage/combinat/root_system/type_reducible.py index da337ebaa96..53dadb9864d 100644 --- a/src/sage/combinat/root_system/type_reducible.py +++ b/src/sage/combinat/root_system/type_reducible.py @@ -525,7 +525,7 @@ def inject_weights(self, i, v): [(1, 1, 0, 0, 0), (0, 0, 0, 1/2, 1/2)] """ shift = self.root_system.cartan_type()._shifts[i] - return self._from_dict( dict([(shift+k, c) for (k,c) in v ])) + return self._from_dict({shift + k: c for k, c in v}) @cached_method def simple_root(self, i): diff --git a/src/sage/combinat/sf/sfa.py b/src/sage/combinat/sf/sfa.py index 47d5e0042c1..cc28bfe7939 100644 --- a/src/sage/combinat/sf/sfa.py +++ b/src/sage/combinat/sf/sfa.py @@ -1982,7 +1982,7 @@ def _change_by_plethysm(self, x, expr, deg_one): # Convert to the power sum p = self.realization_of().power() p_x = p(x) - expr_k = lambda k: expr.subs(**dict([(str(x),x**k) for x in deg_one])) + expr_k = lambda k: expr.subs(**{str(x): x**k for x in deg_one}) f = lambda m,c: (m, c*prod([expr_k(k) for k in m])) return self(p_x.map_item(f)) diff --git a/src/sage/crypto/mq/rijndael_gf.py b/src/sage/crypto/mq/rijndael_gf.py index dc75f5d165b..132e7356d24 100644 --- a/src/sage/crypto/mq/rijndael_gf.py +++ b/src/sage/crypto/mq/rijndael_gf.py @@ -613,8 +613,8 @@ def __call__(self, text, key, algorithm='encrypt', format='hex'): elif algorithm == 'decrypt': return self.decrypt(text, key, format) else: - raise ValueError(("keyword 'algorithm' must be either 'encrypt' " - "or 'decrypt'")) + raise ValueError("keyword 'algorithm' must be either 'encrypt' " + "or 'decrypt'") def __repr__(self): r""" @@ -981,8 +981,8 @@ def encrypt(self, plain, key, format='hex'): key_state = self._bin_to_GF(key) roundKeys = self.expand_key(key_state) else: - raise ValueError(("'format' keyword must be either 'hex' or " - "'binary'")) + raise ValueError("'format' keyword must be either 'hex' or " + "'binary'") state = self.add_round_key(state, roundKeys[0]) for r in range(self._Nr-1): @@ -1057,8 +1057,8 @@ def decrypt(self, ciphertext, key, format='hex'): elif format == 'binary': if not isinstance(ciphertext, str) or \ any(c not in '01' for c in ciphertext): - raise TypeError(("'ciphertext' keyword must be a binary " - "string")) + raise TypeError("'ciphertext' keyword must be a binary " + "string") if len(ciphertext) != 32 * self._Nb: msg = "'ciphertext' keyword's length must be {0}, not {1}" raise ValueError(msg.format(32 * self._Nb, len(ciphertext))) @@ -1072,8 +1072,8 @@ def decrypt(self, ciphertext, key, format='hex'): key_state = self._bin_to_GF(key) roundKeys = self.expand_key(key_state) else: - raise ValueError(("'format' keyword must be either \'hex\' or " - "'binary'")) + raise ValueError("'format' keyword must be either \'hex\' or " + "'binary'") state = self.add_round_key(state, roundKeys[self._Nr]) state = self.shift_rows(state, algorithm='decrypt') @@ -1874,8 +1874,8 @@ def _sub_bytes_pc(self, row, col, algorithm='encrypt', no_inversion=False): else: return result ** 254 else: - raise ValueError(("keyword 'algorithm' must be either 'encrypt' " - "or 'decrypt'")) + raise ValueError("keyword 'algorithm' must be either 'encrypt' " + "or 'decrypt'") def _srd(self, el, algorithm='encrypt'): r""" @@ -1910,8 +1910,8 @@ def _srd(self, el, algorithm='encrypt'): state = [el] + [self._F.zero()]*((4 * self._Nb)-1) return p(state) ** 254 else: - raise ValueError(("keyword 'algorithm' must be either 'encrypt' " - "or 'decrypt'")) + raise ValueError("keyword 'algorithm' must be either 'encrypt' " + "or 'decrypt'") def sub_bytes(self, state, algorithm='encrypt'): r""" @@ -2010,8 +2010,8 @@ def _mix_columns_pc(self, row, col, algorithm='encrypt'): elif algorithm == 'decrypt': coeffs = self._mixcols_D else: - raise ValueError(("keyword 'algorithm' must be either 'encrypt' " - "or 'decrypt'")) + raise ValueError("keyword 'algorithm' must be either 'encrypt' " + "or 'decrypt'") return sum([coeffs[row,k] * self.state_vrs[k,col] for k in range(4)]) def mix_columns(self, state, algorithm='encrypt'): @@ -2109,8 +2109,8 @@ def _shift_rows_pc(self, row, col, algorithm='encrypt'): elif algorithm == 'decrypt': offs = self._shiftrows_offsets_D else: - raise ValueError(("keyword 'algorithm' must be either 'encrypt' " - "or 'decrypt'")) + raise ValueError("keyword 'algorithm' must be either 'encrypt' " + "or 'decrypt'") return self.state_vrs[row, (col + offs[4 - self._Nb][row]) % 4] def shift_rows(self, state, algorithm='encrypt'): diff --git a/src/sage/data_structures/stream.py b/src/sage/data_structures/stream.py index ae3cbb71ecd..ddca8fb26b2 100644 --- a/src/sage/data_structures/stream.py +++ b/src/sage/data_structures/stream.py @@ -107,7 +107,7 @@ lazy_import('sage.combinat.sf.sfa', ['_variables_recursive', '_raise_variables']) -class Stream(): +class Stream: """ Abstract base class for all streams. @@ -2410,7 +2410,7 @@ def stretched_power_restrict_degree(self, i, m, d): _raise_variables(c, i, self._degree_one) for mon, c in power_d} else: - terms = {tuple((mu.stretch(i) for mu in mon)): + terms = {tuple(mu.stretch(i) for mu in mon): _raise_variables(c, i, self._degree_one) for mon, c in power_d} return self._basis(self._p.element_class(self._p, terms)) diff --git a/src/sage/databases/cremona.py b/src/sage/databases/cremona.py index abfbe46d4ac..44c8fbcdc7f 100644 --- a/src/sage/databases/cremona.py +++ b/src/sage/databases/cremona.py @@ -1122,10 +1122,10 @@ def iter_optimal(self, conductors): if N == 990: for c in self.__connection__.cursor().execute('SELECT class ' + 'FROM t_class WHERE conductor=990'): - if c[0][-1] == u'h': - yield self.elliptic_curve(c[0]+u'3') + if c[0][-1] == 'h': + yield self.elliptic_curve(c[0]+'3') else: - yield self.elliptic_curve(c[0]+u'1') + yield self.elliptic_curve(c[0]+'1') continue for c in self.__connection__.cursor().execute('SELECT curve ' + 'FROM t_curve,t_class USING(class) WHERE curve=class||1 ' diff --git a/src/sage/databases/findstat.py b/src/sage/databases/findstat.py index 89cd74f457e..c872ed19d3d 100644 --- a/src/sage/databases/findstat.py +++ b/src/sage/databases/findstat.py @@ -4351,7 +4351,7 @@ def first_terms(self, function, level=None): g = (x for x in self._sageconstructor_overridden if self.element_level(x) == level) - return lazy_list(((x, function(x)) for x in g)) + return lazy_list((x, function(x)) for x in g) def id(self): r""" diff --git a/src/sage/databases/sql_db.py b/src/sage/databases/sql_db.py index 64aa74f6b2d..fad05a0add9 100644 --- a/src/sage/databases/sql_db.py +++ b/src/sage/databases/sql_db.py @@ -254,7 +254,7 @@ def construct_skeleton(database): exe1 = cur.execute("PRAGMA table_info(%s)" % table[0]) for col in exe1.fetchall(): if not col[2]: - typ = u'NOTYPE' + typ = 'NOTYPE' else: typ = col[2] skeleton[table[0]][col[1]] = {'sql':typ, @@ -482,7 +482,7 @@ def __init__(self, database, *args, **kwds): else: self.__query_string__ = kwds['query_string'] if 'param_tuple' in kwds: - self.__param_tuple__ = tuple((str(x) for x in kwds['param_tuple'])) + self.__param_tuple__ = tuple(str(x) for x in kwds['param_tuple']) else: self.__param_tuple__ = tuple() return @@ -2164,7 +2164,7 @@ def add_rows(self, table_name, rows, entry_order=None): if self.__read_only__: raise RuntimeError('Cannot add rows to read only database.') quest = '(' + ', '.join('?' for i in rows[0]) + ')' - strows = [tuple((str(entry) for entry in row)) for row in rows] + strows = [tuple(str(entry) for entry in row) for row in rows] if entry_order is not None: self.__connection__.executemany('INSERT INTO ' + table_name diff --git a/src/sage/doctest/control.py b/src/sage/doctest/control.py index e6fcc29a61b..d32314b89ad 100644 --- a/src/sage/doctest/control.py +++ b/src/sage/doctest/control.py @@ -338,7 +338,7 @@ def skipfile(filename, tested_optional_tags=False, *, return False -class Logger(): +class Logger: r""" File-like object which implements writing to multiple files at once. diff --git a/src/sage/doctest/external.py b/src/sage/doctest/external.py index a80b8ac555e..56727bd79f6 100644 --- a/src/sage/doctest/external.py +++ b/src/sage/doctest/external.py @@ -379,7 +379,7 @@ def external_software() -> list[str]: external_software = external_software() -class AvailableSoftware(): +class AvailableSoftware: """ This class keeps the set of available software whose availability is detected lazily from the list of external software. diff --git a/src/sage/doctest/fixtures.py b/src/sage/doctest/fixtures.py index 033b0671c06..ee812a8ecc9 100644 --- a/src/sage/doctest/fixtures.py +++ b/src/sage/doctest/fixtures.py @@ -112,7 +112,7 @@ def sorted_pairs(iterable, pairs=False): return repr(val) -class AttributeAccessTracerHelper(): +class AttributeAccessTracerHelper: def __init__(self, delegate, prefix=" ", reads=True): r""" @@ -223,7 +223,7 @@ def set(self, name, val): setattr(self.delegate, name, val) -class AttributeAccessTracerProxy(): +class AttributeAccessTracerProxy: def __init__(self, delegate, **kwds): r""" diff --git a/src/sage/doctest/forker.py b/src/sage/doctest/forker.py index dfe57f59b0b..83681163942 100644 --- a/src/sage/doctest/forker.py +++ b/src/sage/doctest/forker.py @@ -2467,7 +2467,7 @@ def kill(self): return True -class DocTestTask(): +class DocTestTask: """ This class encapsulates the tests from a single source. diff --git a/src/sage/doctest/parsing.py b/src/sage/doctest/parsing.py index d9b054ae2dd..0bc4965cd09 100644 --- a/src/sage/doctest/parsing.py +++ b/src/sage/doctest/parsing.py @@ -652,7 +652,7 @@ def reduce_hex(fingerprints): return "%032x" % res -class OriginalSource(): +class OriginalSource: r""" Context swapping out the pre-parsed source with the original for better reporting. diff --git a/src/sage/doctest/sources.py b/src/sage/doctest/sources.py index 68d95d1cf26..78c45195970 100644 --- a/src/sage/doctest/sources.py +++ b/src/sage/doctest/sources.py @@ -124,7 +124,7 @@ def get_basename(path): return basename -class DocTestSource(): +class DocTestSource: """ This class provides a common base class for different sources of doctests. diff --git a/src/sage/dynamics/arithmetic_dynamics/berkovich_ds.py b/src/sage/dynamics/arithmetic_dynamics/berkovich_ds.py index 6995f61f463..0c27d8e2bde 100644 --- a/src/sage/dynamics/arithmetic_dynamics/berkovich_ds.py +++ b/src/sage/dynamics/arithmetic_dynamics/berkovich_ds.py @@ -869,7 +869,7 @@ def __call__(self, x, type_3_pole_check=True): else: new_poly.append(ring_of_integers(i).mod(ideal)) new_poly = R(new_poly) - fraction.append((new_poly)) + fraction.append(new_poly) gcd = fraction[0].gcd(fraction[1]) num = fraction[0].quo_rem(gcd)[0] dem = fraction[1].quo_rem(gcd)[0] diff --git a/src/sage/dynamics/cellular_automata/glca.py b/src/sage/dynamics/cellular_automata/glca.py index dbd7bdc6fc3..ea84884755b 100644 --- a/src/sage/dynamics/cellular_automata/glca.py +++ b/src/sage/dynamics/cellular_automata/glca.py @@ -363,24 +363,24 @@ def _unicode_art_(self, number=None): number = len(self._states) space = len(self._states[:number]) * 2 - 1 - ret = UnicodeArt([u' '*space + u'◾']) + ret = UnicodeArt([' '*space + '◾']) space += 1 for i,state in enumerate(self._states[:number]): - temp = u' '*(space-2) - last = u' ' + temp = ' '*(space-2) + last = ' ' for x in state: if x & 0x4: - if last == u'╱': - temp += u'╳' + if last == '╱': + temp += '╳' else: - temp += u'╲' + temp += '╲' else: temp += last - temp += u'│' if x & 0x2 else ' ' - last = u'╱' if x & 0x1 else ' ' + temp += '│' if x & 0x2 else ' ' + last = '╱' if x & 0x1 else ' ' ret *= UnicodeArt([temp + last]) space -= 1 - ret *= UnicodeArt([u' '*space + u' '.join(u'◾' for dummy in range(2*i+1))]) + ret *= UnicodeArt([' '*space + ' '.join('◾' for dummy in range(2*i+1))]) space -= 1 return ret diff --git a/src/sage/dynamics/complex_dynamics/mandel_julia.py b/src/sage/dynamics/complex_dynamics/mandel_julia.py index 87e98ec084d..f21ffca80e4 100644 --- a/src/sage/dynamics/complex_dynamics/mandel_julia.py +++ b/src/sage/dynamics/complex_dynamics/mandel_julia.py @@ -430,6 +430,7 @@ def external_ray(theta, **kwds): pixel[int(k[0]), int(k[1])] = tuple(ray_color) return M + def kneading_sequence(theta): r""" Determines the kneading sequence for an angle theta in RR/ZZ which diff --git a/src/sage/env.py b/src/sage/env.py index 0f287145814..bbeea046314 100644 --- a/src/sage/env.py +++ b/src/sage/env.py @@ -332,7 +332,7 @@ def get_cblas_pc_module_name() -> str: """ import pkgconfig cblas_pc_modules = CBLAS_PC_MODULES.split(':') - return next((blas_lib for blas_lib in cblas_pc_modules if pkgconfig.exists(blas_lib))) + return next(blas_lib for blas_lib in cblas_pc_modules if pkgconfig.exists(blas_lib)) default_required_modules = ('fflas-ffpack', 'givaro', 'gsl', 'linbox', 'Singular', diff --git a/src/sage/features/__init__.py b/src/sage/features/__init__.py index 81602180d80..e02015a5710 100644 --- a/src/sage/features/__init__.py +++ b/src/sage/features/__init__.py @@ -467,7 +467,7 @@ def __str__(self): return "\n".join(lines) -class FeatureTestResult(): +class FeatureTestResult: r""" The result of a :meth:`Feature.is_present` call. diff --git a/src/sage/functions/hypergeometric.py b/src/sage/functions/hypergeometric.py index 717f0c5b763..5431d15ce18 100644 --- a/src/sage/functions/hypergeometric.py +++ b/src/sage/functions/hypergeometric.py @@ -406,7 +406,7 @@ def _tderivative_(self, a, b, z, *args, **kwargs): return (t * derivative(z, diff_param) * hypergeometric([c + 1 for c in a], [c + 1 for c in b], z)) - class EvaluationMethods(): + class EvaluationMethods: def _fast_callable_(self, a, b, z, etb): """ @@ -1026,7 +1026,7 @@ def _derivative_(self, a, b, z, diff_param): raise NotImplementedError('derivative of hypergeometric function ' 'with respect to parameters') - class EvaluationMethods(): + class EvaluationMethods: def generalized(self, a, b, z): """ Return as a generalized hypergeometric function. @@ -1132,7 +1132,7 @@ def _derivative_(self, a, b, z, diff_param): raise NotImplementedError('derivative of hypergeometric function ' 'with respect to parameters') - class EvaluationMethods(): + class EvaluationMethods: def generalized(self, a, b, z): """ Return in terms of the generalized hypergeometric function. diff --git a/src/sage/functions/piecewise.py b/src/sage/functions/piecewise.py index 4e0274f810e..3dae82fb589 100644 --- a/src/sage/functions/piecewise.py +++ b/src/sage/functions/piecewise.py @@ -319,7 +319,7 @@ def _tderivative_(self, parameters, variable, *args, **kwds): for domain, func in parameters], var=variable) - class EvaluationMethods(): + class EvaluationMethods: def __pow__(self, parameters, variable, n): """ diff --git a/src/sage/game_theory/matching_game.py b/src/sage/game_theory/matching_game.py index 5b3f081bf10..7a51988baec 100644 --- a/src/sage/game_theory/matching_game.py +++ b/src/sage/game_theory/matching_game.py @@ -939,7 +939,7 @@ def solve(self, invert=False): return {key: self._sol_dict[key][0] for key in self._suitors} -class Player(): +class Player: r""" A class to act as a data holder for the players used of the matching games. diff --git a/src/sage/game_theory/normal_form_game.py b/src/sage/game_theory/normal_form_game.py index 8f19e4842e1..e46e96c2b32 100644 --- a/src/sage/game_theory/normal_form_game.py +++ b/src/sage/game_theory/normal_form_game.py @@ -2783,7 +2783,7 @@ def _is_degenerate_pure(self, certificate=False): return False -class _Player(): +class _Player: def __init__(self, num_strategies): r""" TESTS:: diff --git a/src/sage/game_theory/parser.py b/src/sage/game_theory/parser.py index 07b62d178f8..6ab62d5b7ff 100644 --- a/src/sage/game_theory/parser.py +++ b/src/sage/game_theory/parser.py @@ -13,7 +13,7 @@ # **************************************************************************** -class Parser(): +class Parser: r""" A class for parsing the outputs of different algorithms called in other software packages. diff --git a/src/sage/games/sudoku.py b/src/sage/games/sudoku.py index c1b3fa8b62d..a500fef808e 100644 --- a/src/sage/games/sudoku.py +++ b/src/sage/games/sudoku.py @@ -468,9 +468,9 @@ def to_latex(self): for row in range(nsquare): for col in range(nsquare): entry = next(gen) - array.append((str(entry) if entry else ' ')) - array.append(('' if col == nsquare - 1 else '&')) - array.append(('\\\\\n' if (row+1) % n else '\\\\\\hline\n')) + array.append(str(entry) if entry else ' ') + array.append('' if col == nsquare - 1 else '&') + array.append('\\\\\n' if (row+1) % n else '\\\\\\hline\n') array.append('\\end{array}') return ''.join(array) diff --git a/src/sage/geometry/fan.py b/src/sage/geometry/fan.py index 9f8403eeeae..86cd4c83c65 100644 --- a/src/sage/geometry/fan.py +++ b/src/sage/geometry/fan.py @@ -1503,9 +1503,7 @@ def FanFace(rays, cones): head.extend(rays_to_index[(n,)] for n in range(self.nrays())) new_order = head + [n for n in new_order if n not in head] # "Invert" this list to a dictionary - labels = {} - for new, old in enumerate(new_order): - labels[old] = new + labels = {old: new for new, old in enumerate(new_order)} L.relabel(labels) elements = [None] * next_index diff --git a/src/sage/geometry/hasse_diagram.py b/src/sage/geometry/hasse_diagram.py index 2e054bcfedc..74a30abed6d 100644 --- a/src/sage/geometry/hasse_diagram.py +++ b/src/sage/geometry/hasse_diagram.py @@ -188,9 +188,7 @@ def default_face_constructor(atoms, coatoms, **kwds): if required_atoms is None or atom in required_atoms) new_order = head + [n for n in new_order if n not in head] # "Invert" this list to a dictionary - labels = {} - for new, old in enumerate(new_order): - labels[old] = new + labels = {old: new for new, old in enumerate(new_order)} L.relabel(labels) # Construct the actual poset elements elements = [None] * next_index diff --git a/src/sage/groups/finitely_presented.py b/src/sage/groups/finitely_presented.py index 8eb469118d3..18221ead12b 100644 --- a/src/sage/groups/finitely_presented.py +++ b/src/sage/groups/finitely_presented.py @@ -362,7 +362,7 @@ def __call__(self, *values, **kwds): return super().__call__(values) -class RewritingSystem(): +class RewritingSystem: """ A class that wraps GAP's rewriting systems. diff --git a/src/sage/homology/chain_complex.py b/src/sage/homology/chain_complex.py index 97111a0cbfa..2f050801f25 100644 --- a/src/sage/homology/chain_complex.py +++ b/src/sage/homology/chain_complex.py @@ -482,15 +482,15 @@ def _unicode_art_(self): from sage.typeset.unicode_art import UnicodeArt def arrow_art(d): - d_str = [u' d_{0} '.format(d)] - arrow = u' <' + u'─' * (len(d_str[0]) - 3) + u' ' + d_str = [' d_{0} '.format(d)] + arrow = ' <' + '─' * (len(d_str[0]) - 3) + ' ' d_str.append(arrow) return UnicodeArt(d_str, baseline=0) def vector_art(d): v = self.vector(d) if not v.degree(): - return UnicodeArt([u'0']) + return UnicodeArt(['0']) w = matrix(v).transpose() return w._unicode_art_() @@ -499,17 +499,17 @@ def vector_art(d): for ordered in chain_complex.ordered_degrees(): ordered = list(reversed(ordered)) if not ordered: - return UnicodeArt([u'0']) + return UnicodeArt(['0']) result_ordered = vector_art(ordered[0] + chain_complex.degree_of_differential()) for n in ordered: result_ordered += arrow_art(n) + vector_art(n) result = [result_ordered] + result if len(result) == 0: - return UnicodeArt([u'0']) + return UnicodeArt(['0']) concatenated = result[0] for r in result[1:]: - concatenated += UnicodeArt([u' ... ']) + r + concatenated += UnicodeArt([' ... ']) + r return concatenated def is_cycle(self): @@ -1721,33 +1721,33 @@ def _unicode_art_(self): def arrow_art(n): d_n = self.differential(n) if not d_n.nrows() or not d_n.ncols(): - return UnicodeArt([u'<──']) + return UnicodeArt(['<──']) d_str = list(d_n._unicode_art_()) - arrow = u'<' + u'─' * (len(d_str[0]) - 1) + arrow = '<' + '─' * (len(d_str[0]) - 1) d_str.append(arrow) return UnicodeArt(d_str) def module_art(n): C_n = self.free_module(n) if not C_n.rank(): - return UnicodeArt([u' 0 ']) + return UnicodeArt([' 0 ']) else: - return UnicodeArt([u' C_{0} '.format(n)]) + return UnicodeArt([' C_{0} '.format(n)]) result = [] for ordered in self.ordered_degrees(): ordered = list(reversed(ordered)) if not ordered: - return UnicodeArt([u'0']) + return UnicodeArt(['0']) result_ordered = module_art(ordered[0] + self.degree_of_differential()) for n in ordered: result_ordered += arrow_art(n) + module_art(n) result = [result_ordered] + result if len(result) == 0: - return UnicodeArt([u'0']) + return UnicodeArt(['0']) concatenated = result[0] for r in result[1:]: - concatenated += UnicodeArt([u' ... ']) + r + concatenated += UnicodeArt([' ... ']) + r return concatenated def _latex_(self): diff --git a/src/sage/homology/chains.py b/src/sage/homology/chains.py index 3489d69286c..41bdf06776c 100644 --- a/src/sage/homology/chains.py +++ b/src/sage/homology/chains.py @@ -25,7 +25,7 @@ from sage.structure.element import coercion_model -class CellComplexReference(): +class CellComplexReference: def __init__(self, cell_complex, degree, cells=None): """ diff --git a/src/sage/interfaces/expect.py b/src/sage/interfaces/expect.py index dddebf0d1df..91f8efcf651 100644 --- a/src/sage/interfaces/expect.py +++ b/src/sage/interfaces/expect.py @@ -85,7 +85,7 @@ # "return", "break", or "continue", raising an exception, ...) -class gc_disabled(): +class gc_disabled: """ This is a "with" statement context manager. Garbage collection is disabled within its scope. Nested usage is properly handled. diff --git a/src/sage/interfaces/four_ti_2.py b/src/sage/interfaces/four_ti_2.py index 6776a9cc512..8d93ce9c5e3 100644 --- a/src/sage/interfaces/four_ti_2.py +++ b/src/sage/interfaces/four_ti_2.py @@ -41,7 +41,7 @@ import os -class FourTi2(): +class FourTi2: r""" An interface to the program 4ti2. diff --git a/src/sage/interfaces/gfan.py b/src/sage/interfaces/gfan.py index a169848c678..a37e8825b5b 100644 --- a/src/sage/interfaces/gfan.py +++ b/src/sage/interfaces/gfan.py @@ -47,7 +47,7 @@ from sage.misc.decorators import rename_keyword -class Gfan(): +class Gfan: """ Interface to Anders Jensen's Groebner Fan program. """ diff --git a/src/sage/interfaces/interface.py b/src/sage/interfaces/interface.py index c15f0342de4..b229e0aa2cd 100644 --- a/src/sage/interfaces/interface.py +++ b/src/sage/interfaces/interface.py @@ -444,9 +444,12 @@ def _relation_symbols(self): sage: symbols[operator.eq] '==' """ - return dict([(operator.eq, self._equality_symbol()), (operator.ne, self._inequality_symbol()), - (operator.lt, self._lessthan_symbol()), (operator.le, "<="), - (operator.gt, self._greaterthan_symbol()), (operator.ge, ">=")]) + return {operator.eq: self._equality_symbol(), + operator.ne: self._inequality_symbol(), + operator.lt: self._lessthan_symbol(), + operator.le: "<=", + operator.gt: self._greaterthan_symbol(), + operator.ge: ">="} def _exponent_symbol(self): """ diff --git a/src/sage/interfaces/maxima_lib.py b/src/sage/interfaces/maxima_lib.py index 1e6f85cfae0..73a9dca1994 100644 --- a/src/sage/interfaces/maxima_lib.py +++ b/src/sage/interfaces/maxima_lib.py @@ -1244,8 +1244,8 @@ def reduce_load_MaximaLib(): sage.functions.other.conjugate: "$CONJUGATE", } # we compile the dictionary -sage_op_dict = dict([(k, EclObject(sage_op_dict[k])) for k in sage_op_dict]) -max_op_dict = dict([(sage_op_dict[k], k) for k in sage_op_dict]) +sage_op_dict = {k: EclObject(sage_op_dict[k]) for k in sage_op_dict} +max_op_dict = {sage_op_dict[k]: k for k in sage_op_dict} # Here we correct the dictionaries for some simple operators @@ -1437,7 +1437,7 @@ def max_at_to_sage(expr): subsvalues = {v.lhs(): v.rhs() for v in max_to_sr(subsarg)} else: v = max_to_sr(subsarg) - subsvalues = dict([(v.lhs(), v.rhs())]) + subsvalues = {v.lhs(): v.rhs()} return SR(arg).subs(subsvalues) diff --git a/src/sage/interfaces/sympy.py b/src/sage/interfaces/sympy.py index 2ccaf13035d..5a380a86271 100644 --- a/src/sage/interfaces/sympy.py +++ b/src/sage/interfaces/sympy.py @@ -418,8 +418,8 @@ def _sympysage_Subs(self): sage: from sympy.core.singleton import S """ args = self.args - substi = dict([(args[1][i]._sage_(), args[2][i]._sage_()) - for i in range(len(args[1]))]) + substi = {args[1][i]._sage_(): args[2][i]._sage_() + for i in range(len(args[1]))} return args[0]._sage_().subs(substi) diff --git a/src/sage/interfaces/tab_completion.py b/src/sage/interfaces/tab_completion.py index fdbe51ffd8e..391872d00bc 100644 --- a/src/sage/interfaces/tab_completion.py +++ b/src/sage/interfaces/tab_completion.py @@ -27,7 +27,7 @@ import builtins -class ExtraTabCompletion(): +class ExtraTabCompletion: def __dir__(self): """ diff --git a/src/sage/knots/knot.py b/src/sage/knots/knot.py index 21dd0b59f12..aaa01cdade9 100644 --- a/src/sage/knots/knot.py +++ b/src/sage/knots/knot.py @@ -200,14 +200,14 @@ def _unicode_art_(self): x, y, xx, yy = xx, yy, x, y if y < b: if xx < a: - M[a][b] = u"╯" + M[a][b] = "╯" else: - M[a][b] = u"╮" + M[a][b] = "╮" else: if xx < a: - M[a][b] = u"╰" + M[a][b] = "╰" else: - M[a][b] = u"╭" + M[a][b] = "╭" for ab, cd in graphe.edge_iterator(labels=False): a, b = ab @@ -215,21 +215,21 @@ def _unicode_art_(self): if a == c: b, d = sorted((b, d)) for i in range(b + 1, d): - M[a][i] = u"─" + M[a][i] = "─" else: a, c = sorted((a, c)) for i in range(a + 1, c): - M[i][b] = u"│" + M[i][b] = "│" if style == 0: - H = u"┿" - V = u"╂" + H = "┿" + V = "╂" elif style == 1: - H = u"━" - V = u"┃" + H = "━" + V = "┃" elif style == 2: - H = u"─" - V = u"│" + H = "─" + V = "│" for x, y in hori: M[x][y] = H diff --git a/src/sage/lfunctions/pari.py b/src/sage/lfunctions/pari.py index 78af0a49b9e..db07629dcfd 100644 --- a/src/sage/lfunctions/pari.py +++ b/src/sage/lfunctions/pari.py @@ -26,7 +26,7 @@ from sage.rings.power_series_ring import PowerSeriesRing -class lfun_generic(): +class lfun_generic: r""" Create a PARI `L`-function (:pari:`lfun` instance). diff --git a/src/sage/libs/gap/context_managers.py b/src/sage/libs/gap/context_managers.py index 539b721af83..611708ad96b 100644 --- a/src/sage/libs/gap/context_managers.py +++ b/src/sage/libs/gap/context_managers.py @@ -45,7 +45,7 @@ from sage.libs.gap.libgap import libgap -class GlobalVariableContext(): +class GlobalVariableContext: def __init__(self, variable, value): """ diff --git a/src/sage/libs/singular/function_factory.py b/src/sage/libs/singular/function_factory.py index c4b0b52372f..939b52fab5b 100644 --- a/src/sage/libs/singular/function_factory.py +++ b/src/sage/libs/singular/function_factory.py @@ -15,7 +15,7 @@ from sage.libs.singular.function import singular_function, lib, list_of_functions -class SingularFunctionFactory(): +class SingularFunctionFactory: """ A convenient interface to libsingular functions. """ diff --git a/src/sage/modular/abvar/abvar.py b/src/sage/modular/abvar/abvar.py index 80f1fd3e7c4..92b1e9f9abe 100644 --- a/src/sage/modular/abvar/abvar.py +++ b/src/sage/modular/abvar/abvar.py @@ -2371,8 +2371,8 @@ def frobenius_polynomial(self, p, var='x'): from .constructor import AbelianVariety decomp = [AbelianVariety(f) for f in self.newform_decomposition('a')] - return prod((s.frobenius_polynomial(p) for s in - decomp)) + return prod(s.frobenius_polynomial(p) for s in + decomp) f = self.newform('a') Kf = f.base_ring() eps = f.character() diff --git a/src/sage/modular/abvar/torsion_subgroup.py b/src/sage/modular/abvar/torsion_subgroup.py index 516acf5f7fd..3630da570be 100644 --- a/src/sage/modular/abvar/torsion_subgroup.py +++ b/src/sage/modular/abvar/torsion_subgroup.py @@ -468,7 +468,7 @@ def multiple_of_order(self, maxp=None, proof=True): return self._multiple_of_order_proof_false # The Gamma0 and Gamma1 case - if all((isinstance(G, Gamma0_class) or isinstance(G, Gamma1_class) for G in A.groups())): + if all(isinstance(G, Gamma0_class) or isinstance(G, Gamma1_class) for G in A.groups()): self._multiple_of_order = self.multiple_of_order_using_frobp() return self._multiple_of_order @@ -569,7 +569,7 @@ def multiple_of_order_using_frobp(self, maxp=None): T = ZZ(1) self.__multiple_of_order_using_frobp = T return T - if not all((isinstance(G, Gamma0_class) or isinstance(G, Gamma1_class) for G in A.groups())): + if not all(isinstance(G, Gamma0_class) or isinstance(G, Gamma1_class) for G in A.groups()): raise NotImplementedError("torsion multiple only implemented for Gamma0 and Gamma1") bnd = ZZ(0) diff --git a/src/sage/modular/arithgroup/tests.py b/src/sage/modular/arithgroup/tests.py index b00e39c0cda..f096b0a0429 100644 --- a/src/sage/modular/arithgroup/tests.py +++ b/src/sage/modular/arithgroup/tests.py @@ -311,7 +311,7 @@ def test_congruence_groups(self): if getattr(G, f)() != getattr(GG, f)(): raise AssertionError("results of %s does not coincide for %s" % (f, G)) - if sorted((G.cusp_width(c) for c in G.cusps())) != GG.cusp_widths(): + if sorted(G.cusp_width(c) for c in G.cusps()) != GG.cusp_widths(): raise AssertionError("Cusps widths are different for %s" % G) for _ in range(20): diff --git a/src/sage/modular/btquotients/btquotient.py b/src/sage/modular/btquotients/btquotient.py index d4bdb13e6b1..280acec8874 100644 --- a/src/sage/modular/btquotients/btquotient.py +++ b/src/sage/modular/btquotients/btquotient.py @@ -2914,7 +2914,7 @@ def _get_hecke_data(self, l): while not V: V = [g for g in self._find_elements_in_order(l * p ** nninc) if prod([self._character(ZZ((v * Matrix(ZZ, 4, 1, g))[0, 0])) - / self._character((p ** (nninc // 2))) + / self._character(p ** (nninc // 2)) for v in self.get_extra_embedding_matrices()]) == 1] if not V: nninc += 2 @@ -2927,7 +2927,7 @@ def _get_hecke_data(self, l): letters = self.get_nontorsion_generators() letters += [g for g in self._find_elements_in_order(1) if prod([self._character(ZZ((v * Matrix(ZZ, 4, 1, g))[0, 0])) - / self._character((p ** (nninc // 2))) + / self._character(p ** (nninc // 2)) for v in self.get_extra_embedding_matrices()]) == 1] n_iters = 0 diff --git a/src/sage/modular/btquotients/pautomorphicform.py b/src/sage/modular/btquotients/pautomorphicform.py index 54acfeeeaa9..53a7d2ac6f6 100644 --- a/src/sage/modular/btquotients/pautomorphicform.py +++ b/src/sage/modular/btquotients/pautomorphicform.py @@ -1161,7 +1161,7 @@ def basis_matrix(self): d = self._k - 1 for e in self._E: try: - g = next((g for g in S[e.label] if g[2])) + g = next(g for g in S[e.label] if g[2]) C = self._U.acting_matrix(self._Sigma0(self.embed_quaternion(g[0])), d).transpose() # Warning - Need to allow the check = True C -= self._U.acting_matrix(self._Sigma0(Matrix(QQ, 2, 2, p ** g[1])), d).transpose() # Warning - Need to allow the check = True stab_conds.append([e.label, C]) @@ -2113,7 +2113,7 @@ def coleman(self, t1, t2, E=None, method='moments', mult=False): assert 0 value += new if mult: - value_exp *= K.teichmuller(((b - d * t1) / (b - d * t2))) ** Integer(c_e.moment(0).rational_reconstruction()) + value_exp *= K.teichmuller((b - d * t1) / (b - d * t2)) ** Integer(c_e.moment(0).rational_reconstruction()) else: print('The available methods are either "moments" or "riemann_sum". The latter is only provided for consistency check, and should not be used in practice.') diff --git a/src/sage/modular/drinfeld_modform/ring.py b/src/sage/modular/drinfeld_modform/ring.py index c113523fc48..d8a4d1184c3 100644 --- a/src/sage/modular/drinfeld_modform/ring.py +++ b/src/sage/modular/drinfeld_modform/ring.py @@ -430,13 +430,11 @@ def _coefficient_forms(self, a): [(T^2 + T)*g1, g1^3 + (T^4 + T)*g2, g1^4*g2 + g1*g2^2, g2^5] """ a = a.numerator() - d = a.degree() poly_ring = PolynomialRing(self._base_ring, self.rank(), 'g') poly_ring_gens = poly_ring.gens() Frob = poly_ring.frobenius_endomorphism() gen = [self._base_ring.gen()] - for g in poly_ring_gens: - gen.append(g) + gen.extend(poly_ring_gens) ore_pol_ring = OrePolynomialRing(poly_ring, Frob, 't') gen = ore_pol_ring(gen) f = sum(c*(gen**idx) for idx, c in enumerate(a.coefficients(sparse=False))) diff --git a/src/sage/modular/pollack_stevens/manin_map.py b/src/sage/modular/pollack_stevens/manin_map.py index 94ba0843131..04120ba5d7d 100644 --- a/src/sage/modular/pollack_stevens/manin_map.py +++ b/src/sage/modular/pollack_stevens/manin_map.py @@ -159,7 +159,7 @@ def unimod_matrices_from_infty(r, s): return [] -class ManinMap(): +class ManinMap: r""" Map from a set of right coset representatives of `\Gamma_0(N)` in `SL_2(\ZZ)` to a coefficient module that satisfies the Manin diff --git a/src/sage/parallel/decorate.py b/src/sage/parallel/decorate.py index b23e997b7e2..8195a440fa2 100644 --- a/src/sage/parallel/decorate.py +++ b/src/sage/parallel/decorate.py @@ -51,7 +51,7 @@ def normalize_input(a): return ((a,), {}) -class Parallel(): +class Parallel: r""" Create a ``parallel``-decorated function. This is the object created by :func:`parallel`. @@ -119,7 +119,7 @@ def __call__(self, f): @instancedoc -class ParallelFunction(): +class ParallelFunction: """ Class which parallelizes a function or class method. This is typically accessed indirectly through @@ -422,7 +422,7 @@ def parallel(p_iter='fork', ncpus=None, **kwds): # def f(...): ... ################################################################### -class Fork(): +class Fork: """ A ``fork`` decorator class. """ diff --git a/src/sage/parallel/map_reduce.py b/src/sage/parallel/map_reduce.py index 239afb6df8b..d284d41e252 100644 --- a/src/sage/parallel/map_reduce.py +++ b/src/sage/parallel/map_reduce.py @@ -628,7 +628,7 @@ class AbortError(Exception): pass -class ActiveTaskCounterDarwin(): +class ActiveTaskCounterDarwin: r""" Handling the number of active tasks. @@ -741,7 +741,7 @@ def abort(self): self._active_tasks.value = 0 -class ActiveTaskCounterPosix(): +class ActiveTaskCounterPosix: r""" Handling the number of active tasks. @@ -884,7 +884,7 @@ def abort(self): # ActiveTaskCounter = ActiveTaskCounterDarwin # to debug Darwin implementation -class RESetMapReduce(): +class RESetMapReduce: r""" Map-Reduce on recursively enumerated sets. diff --git a/src/sage/parallel/use_fork.py b/src/sage/parallel/use_fork.py index bc5293e0248..36269127b80 100644 --- a/src/sage/parallel/use_fork.py +++ b/src/sage/parallel/use_fork.py @@ -20,7 +20,7 @@ from sage.misc.timing import walltime -class WorkerData(): +class WorkerData: """ Simple class which stores data about a running ``p_iter_fork`` worker. @@ -55,7 +55,7 @@ def __init__(self, input_value, starttime=None, failure=""): self.failure = failure -class p_iter_fork(): +class p_iter_fork: """ A parallel iterator implemented using ``fork()``. diff --git a/src/sage/plot/streamline_plot.py b/src/sage/plot/streamline_plot.py index b69a05b37bf..2801446433a 100644 --- a/src/sage/plot/streamline_plot.py +++ b/src/sage/plot/streamline_plot.py @@ -296,9 +296,8 @@ def streamline_plot(f_g, xrange, yrange, **options): else: options['density'] = float(options['density']) - xpos_array, ypos_array, xvec_array, yvec_array = [], [], [], [] - for x in xsrange(*ranges[0], include_endpoint=True): - xpos_array.append(x) + ypos_array, xvec_array, yvec_array = [], [], [] + xpos_array = list(xsrange(*ranges[0], include_endpoint=True)) for y in xsrange(*ranges[1], include_endpoint=True): ypos_array.append(y) xvec_row, yvec_row = [], [] diff --git a/src/sage/quivers/path_semigroup.py b/src/sage/quivers/path_semigroup.py index cb141c02751..1b9fe359fba 100644 --- a/src/sage/quivers/path_semigroup.py +++ b/src/sage/quivers/path_semigroup.py @@ -362,7 +362,7 @@ def _element_constructor_(self, data, check=True): path = [] else: # a list of edges if any(len(x) != 3 for x in data): - x = next((x for x in data if len(x) != 3)) + x = next(x for x in data if len(x) != 3) raise ValueError("each edge must be a triple, got {}".format(x)) start = data[0][0] end = data[-1][1] diff --git a/src/sage/repl/configuration.py b/src/sage/repl/configuration.py index a87ee896307..68b2fbb9f8b 100644 --- a/src/sage/repl/configuration.py +++ b/src/sage/repl/configuration.py @@ -37,7 +37,7 @@ SAGE_EXTENSION = 'sage' -class SageIpythonConfiguration(): +class SageIpythonConfiguration: def _doctest_mode(self): """ diff --git a/src/sage/repl/display/fancy_repr.py b/src/sage/repl/display/fancy_repr.py index bb1f41ded56..044f8e3f6b2 100644 --- a/src/sage/repl/display/fancy_repr.py +++ b/src/sage/repl/display/fancy_repr.py @@ -24,7 +24,7 @@ _baseclass_reprs = (object.__repr__,) -class ObjectReprABC(): +class ObjectReprABC: """ The abstract base class of an object representer. diff --git a/src/sage/repl/display/util.py b/src/sage/repl/display/util.py index 450d1e0db62..5b931a67673 100644 --- a/src/sage/repl/display/util.py +++ b/src/sage/repl/display/util.py @@ -16,7 +16,7 @@ # **************************************************************************** -class TallListFormatter(): +class TallListFormatter: """ Special representation for lists with tall entries (e.g. matrices). diff --git a/src/sage/repl/interface_magic.py b/src/sage/repl/interface_magic.py index a426dfdda07..d4c28dc49ac 100644 --- a/src/sage/repl/interface_magic.py +++ b/src/sage/repl/interface_magic.py @@ -80,7 +80,7 @@ """ -class InterfaceMagic(): +class InterfaceMagic: @classmethod def all_iter(cls): diff --git a/src/sage/repl/interpreter.py b/src/sage/repl/interpreter.py index c0f52dc7c30..87cb3813a75 100644 --- a/src/sage/repl/interpreter.py +++ b/src/sage/repl/interpreter.py @@ -197,7 +197,7 @@ def preparser(on=True): ############################## # Sage[Terminal]InteractiveShell ############################## -class SageShellOverride(): +class SageShellOverride: """ Mixin to override methods in IPython's [Terminal]InteractiveShell classes. diff --git a/src/sage/repl/ipython_extension.py b/src/sage/repl/ipython_extension.py index 3c008d1cd65..b6fc42bbb37 100644 --- a/src/sage/repl/ipython_extension.py +++ b/src/sage/repl/ipython_extension.py @@ -418,7 +418,7 @@ def fortran(self, line, cell): return fortran(cell) -class SageCustomizations(): +class SageCustomizations: def __init__(self, shell=None): """ diff --git a/src/sage/repl/ipython_kernel/install.py b/src/sage/repl/ipython_kernel/install.py index 3a2efb4ab64..0b340e86238 100644 --- a/src/sage/repl/ipython_kernel/install.py +++ b/src/sage/repl/ipython_kernel/install.py @@ -26,7 +26,7 @@ ) -class SageKernelSpec(): +class SageKernelSpec: def __init__(self, prefix=None): """ diff --git a/src/sage/repl/ipython_kernel/widgets.py b/src/sage/repl/ipython_kernel/widgets.py index 3fa000f70df..42d674b7c9a 100644 --- a/src/sage/repl/ipython_kernel/widgets.py +++ b/src/sage/repl/ipython_kernel/widgets.py @@ -84,7 +84,7 @@ def description(self, value): pass -class TransformWidget(): +class TransformWidget: """ A mixin class for a widget to transform the bare widget value for use in interactive functions. @@ -383,7 +383,7 @@ class Grid(TransformWidget, HBox, ValueWidget): value = List() description = Unicode() - def __init__(self, nrows, ncols, make_widget, description=u"", transform=None): + def __init__(self, nrows, ncols, make_widget, description="", transform=None): """ Create a :class:`Grid` widget. diff --git a/src/sage/repl/rich_output/display_manager.py b/src/sage/repl/rich_output/display_manager.py index 473e860ba42..583d0d870b5 100644 --- a/src/sage/repl/rich_output/display_manager.py +++ b/src/sage/repl/rich_output/display_manager.py @@ -103,7 +103,7 @@ class RichReprWarning(UserWarning): pass -class restricted_output(): +class restricted_output: def __init__(self, display_manager, output_classes): """ diff --git a/src/sage/repl/rich_output/output_basic.py b/src/sage/repl/rich_output/output_basic.py index 68bbf92df9d..70257f7f4ed 100644 --- a/src/sage/repl/rich_output/output_basic.py +++ b/src/sage/repl/rich_output/output_basic.py @@ -264,9 +264,9 @@ def example(cls): ⎜ 3 -1 0⎟ ⎝ -1 -1 0⎠ """ - return cls(u'⎛-11 0 1⎞\n' - u'⎜ 3 -1 0⎟\n' - u'⎝ -1 -1 0⎠') + return cls('⎛-11 0 1⎞\n' + '⎜ 3 -1 0⎟\n' + '⎝ -1 -1 0⎠') def print_to_stdout(self): """ diff --git a/src/sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py b/src/sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py index 2147409845f..9eaf85376ca 100644 --- a/src/sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py +++ b/src/sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py @@ -3501,7 +3501,7 @@ def sum(self): # Compute the sum's numerator and denominator. R = self.denominator_ring - summy = sum((f.quotient() for f in self)) + summy = sum(f.quotient() for f in self) numer = summy.numerator() denom = R(summy.denominator()) diff --git a/src/sage/rings/continued_fraction_gosper.py b/src/sage/rings/continued_fraction_gosper.py index 980cf62f72f..619008df426 100644 --- a/src/sage/rings/continued_fraction_gosper.py +++ b/src/sage/rings/continued_fraction_gosper.py @@ -36,7 +36,7 @@ from sage.rings.integer import Integer -class gosper_iterator(): +class gosper_iterator: r""" Iterable for the partial quotients of `(a*x+b)/(c*x+d)`, where `a, b, c, d` are integers, and `x` is a continued fraction. diff --git a/src/sage/rings/invariants/invariant_theory.py b/src/sage/rings/invariants/invariant_theory.py index dc370bdf560..fb953f98813 100644 --- a/src/sage/rings/invariants/invariant_theory.py +++ b/src/sage/rings/invariants/invariant_theory.py @@ -3959,7 +3959,7 @@ def syzygy(self, Delta, Theta, Phi, Theta_prime, Delta_prime, U, V, T, T_prime, ###################################################################### -class InvariantTheoryFactory(): +class InvariantTheoryFactory: """ Factory object for invariants of multilinear forms. diff --git a/src/sage/rings/lazy_series.py b/src/sage/rings/lazy_series.py index f34188ba764..8520ad33f68 100644 --- a/src/sage/rings/lazy_series.py +++ b/src/sage/rings/lazy_series.py @@ -476,7 +476,7 @@ def coefficients(self, n=None): return lazy_list(coeffs) # flatten out the generator in the multivariate case - return lazy_list(chain.from_iterable((coeff.coefficients() for coeff in coeffs))) + return lazy_list(chain.from_iterable(coeff.coefficients() for coeff in coeffs)) if isinstance(self, LazyPowerSeries) and self.parent()._arity == 1: from sage.misc.superseded import deprecation @@ -486,7 +486,7 @@ def coefficients(self, n=None): return list(islice(coeffs, n)) # flatten out the generator in the multivariate case - return list(islice(chain.from_iterable((coeff.coefficients() for coeff in coeffs)), n)) + return list(islice(chain.from_iterable(coeff.coefficients() for coeff in coeffs), n)) def map_coefficients(self, f): r""" diff --git a/src/sage/rings/multi_power_series_ring_element.py b/src/sage/rings/multi_power_series_ring_element.py index b7731d59f74..cdea63e5e12 100644 --- a/src/sage/rings/multi_power_series_ring_element.py +++ b/src/sage/rings/multi_power_series_ring_element.py @@ -2095,7 +2095,7 @@ def laurent_series(self): raise NotImplementedError("laurent_series not defined for multivariate power series.") -class MO(): +class MO: """ Object representing a zero element with given precision. diff --git a/src/sage/rings/number_field/small_primes_of_degree_one.py b/src/sage/rings/number_field/small_primes_of_degree_one.py index 25c06fb5b60..ff30a006bba 100644 --- a/src/sage/rings/number_field/small_primes_of_degree_one.py +++ b/src/sage/rings/number_field/small_primes_of_degree_one.py @@ -96,7 +96,7 @@ from sage.rings.integer_ring import ZZ -class Small_primes_of_degree_one_iter(): +class Small_primes_of_degree_one_iter: r""" Iterator that finds primes of a number field of absolute degree one and bounded small prime norm. diff --git a/src/sage/rings/padics/lattice_precision.py b/src/sage/rings/padics/lattice_precision.py index 8b1d4a9cfba..f5a5ce09a76 100644 --- a/src/sage/rings/padics/lattice_precision.py +++ b/src/sage/rings/padics/lattice_precision.py @@ -2739,7 +2739,7 @@ def precision_lattice(self, elements=None): return M -class pAdicLatticeElementWeakProxy(): +class pAdicLatticeElementWeakProxy: r""" The implementations of :class:`DifferentialPrecisionGeneric` hold weak references to :class:`pAdicLatticeElement`. They are stored in diff --git a/src/sage/rings/polynomial/multi_polynomial_element.py b/src/sage/rings/polynomial/multi_polynomial_element.py index 14a7bae649f..5f126259fa9 100644 --- a/src/sage/rings/polynomial/multi_polynomial_element.py +++ b/src/sage/rings/polynomial/multi_polynomial_element.py @@ -1915,7 +1915,7 @@ def _derivative(self, var=None): if index == -1: # var is not a generator; do term-by-term differentiation recursively # var may be, for example, a generator of the base ring - d = dict([(e, x._derivative(var)) for (e, x) in self.dict().items()]) + d = {e: x._derivative(var) for e, x in self.dict().items()} d = polydict.PolyDict(d, check=False) d.remove_zeros() return MPolynomial_polydict(P, d) diff --git a/src/sage/rings/polynomial/polynomial_quotient_ring_element.py b/src/sage/rings/polynomial/polynomial_quotient_ring_element.py index 919b4b856d4..c167caeb352 100644 --- a/src/sage/rings/polynomial/polynomial_quotient_ring_element.py +++ b/src/sage/rings/polynomial/polynomial_quotient_ring_element.py @@ -145,7 +145,7 @@ def __init__(self, parent, polynomial, check=True): Q = P(0) X = P.gen() while R.degree() >= B.degree(): - S = P((R.leading_coefficient()/B.leading_coefficient())) * X**(R.degree()-B.degree()) + S = P(R.leading_coefficient()/B.leading_coefficient()) * X**(R.degree()-B.degree()) Q = Q + S R = R - S*B polynomial = R diff --git a/src/sage/rings/valuation/valuation.py b/src/sage/rings/valuation/valuation.py index bbc5bdf1db0..2deeb100ffc 100644 --- a/src/sage/rings/valuation/valuation.py +++ b/src/sage/rings/valuation/valuation.py @@ -1043,7 +1043,7 @@ def _ge_(self, other): return super()._ge_(other) -class MacLaneApproximantNode(): +class MacLaneApproximantNode: r""" A node in the tree computed by :meth:`DiscreteValuation.mac_lane_approximants`. diff --git a/src/sage/sat/converters/anf2cnf.py b/src/sage/sat/converters/anf2cnf.py index eafc8b0a440..2316551fa2d 100644 --- a/src/sage/sat/converters/anf2cnf.py +++ b/src/sage/sat/converters/anf2cnf.py @@ -9,5 +9,5 @@ """ -class ANF2CNFConverter(): +class ANF2CNFConverter: pass diff --git a/src/sage/sat/converters/polybori.py b/src/sage/sat/converters/polybori.py index d57f1c12c02..27437c472ec 100644 --- a/src/sage/sat/converters/polybori.py +++ b/src/sage/sat/converters/polybori.py @@ -237,7 +237,7 @@ def choose(s): while not rest.empty(): l = choose(rest) l_variables = set(l.variables()) - block_dict = dict([(v, 1 if v in l_variables else 0) for v in variables]) + block_dict = {v: (1 if v in l_variables else 0) for v in variables} l = l.set() self.random_generator.shuffle(variables) for v in variables: diff --git a/src/sage/schemes/toric/fano_variety.py b/src/sage/schemes/toric/fano_variety.py index 77a14643e4b..113399a9c38 100755 --- a/src/sage/schemes/toric/fano_variety.py +++ b/src/sage/schemes/toric/fano_variety.py @@ -532,9 +532,8 @@ def CPRFanoToricVariety(Delta=None, raise ValueError("the origin (point #%d) cannot be used for a " "coordinate!\nGot: %s" % (Delta_polar.origin(), coordinate_points)) - point_to_ray = {} - for n, point in enumerate(coordinate_points): - point_to_ray[point] = n + point_to_ray = {point: n + for n, point in enumerate(coordinate_points)} # This can be simplified if LatticePolytopeClass is adjusted. rays = [Delta_polar.point(p) for p in coordinate_points] # Check/normalize charts and construct the fan based on them. @@ -1229,9 +1228,8 @@ def resolve(self, **kwds): "subdivision!" % Delta_polar.origin()) if new_points: coordinate_points = coordinate_points + new_points - point_to_ray = {} - for n, point in enumerate(coordinate_points): - point_to_ray[point] = n + point_to_ray = {point: n + for n, point in enumerate(coordinate_points)} else: point_to_ray = self._point_to_ray new_rays = [Delta_polar.point(point) for point in new_points] diff --git a/src/sage/sets/integer_range.py b/src/sage/sets/integer_range.py index 1406ddc9b28..3b95506f591 100644 --- a/src/sage/sets/integer_range.py +++ b/src/sage/sets/integer_range.py @@ -384,7 +384,7 @@ def cardinality(self): sage: IntegerRange(123,12,4).cardinality() 0 """ - return (abs((self._end+self._step-self._begin))-1) // abs(self._step) + return (abs(self._end+self._step-self._begin)-1) // abs(self._step) def _repr_(self): """ diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index 55d5639e706..5bda2d79169 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -209,7 +209,7 @@ def Set(X=None, category=None): return Set_object_enumerated(X, category=category) -class Set_base(): +class Set_base: r""" Abstract base class for sets, not necessarily parents. """ diff --git a/src/sage/sets/set_from_iterator.py b/src/sage/sets/set_from_iterator.py index 0020ca080a1..6f68f1245b8 100644 --- a/src/sage/sets/set_from_iterator.py +++ b/src/sage/sets/set_from_iterator.py @@ -450,7 +450,7 @@ def clear_cache(self): # TODO: move it in sage.misc ? @instancedoc -class Decorator(): +class Decorator: r""" Abstract class that manage documentation and sources of the wrapped object. @@ -838,7 +838,7 @@ def __get__(self, inst, cls): **self.options) -class EnumeratedSetFromIterator_method_decorator(): +class EnumeratedSetFromIterator_method_decorator: r""" Decorator for enumerated set built from a method. diff --git a/src/sage/structure/global_options.py b/src/sage/structure/global_options.py index 854a93e6009..0f3308cc80f 100644 --- a/src/sage/structure/global_options.py +++ b/src/sage/structure/global_options.py @@ -514,7 +514,7 @@ class options(GlobalOptions): from sage.misc.instancedoc import instancedoc -class Option(): +class Option: r""" An option. diff --git a/src/sage/structure/indexed_generators.py b/src/sage/structure/indexed_generators.py index 9f3c8b710ea..7586eb06aaf 100644 --- a/src/sage/structure/indexed_generators.py +++ b/src/sage/structure/indexed_generators.py @@ -14,7 +14,7 @@ from sage.structure.category_object import normalize_names -class IndexedGenerators(): +class IndexedGenerators: r"""nodetex Abstract base class for parents whose elements consist of generators indexed by an arbitrary set. diff --git a/src/sage/structure/proof/proof.py b/src/sage/structure/proof/proof.py index f214864cac2..c8c2df4cafe 100644 --- a/src/sage/structure/proof/proof.py +++ b/src/sage/structure/proof/proof.py @@ -232,7 +232,7 @@ def get_flag(t=None, subsystem=None): return t -class WithProof(): +class WithProof: """ Use :class:`WithProof` to temporarily set the value of one of the proof systems for a block of code, with a guarantee that it will be set diff --git a/src/sage/structure/test_factory.py b/src/sage/structure/test_factory.py index 11b90f48f20..707feb0d409 100644 --- a/src/sage/structure/test_factory.py +++ b/src/sage/structure/test_factory.py @@ -21,7 +21,7 @@ from sage.structure.factory import UniqueFactory -class A(): +class A: # something we can weakref pass diff --git a/src/sage/symbolic/constants.py b/src/sage/symbolic/constants.py index f7177a24994..20a293fbb7b 100644 --- a/src/sage/symbolic/constants.py +++ b/src/sage/symbolic/constants.py @@ -273,7 +273,7 @@ def unpickle_Constant(class_name, name, conversions, latex, mathml, domain): @richcmp_method -class Constant(): +class Constant: def __init__(self, name, conversions=None, latex=None, mathml='', domain='complex'): """ diff --git a/src/sage/symbolic/function_factory.py b/src/sage/symbolic/function_factory.py index d626eb9bd65..057d1e07811 100644 --- a/src/sage/symbolic/function_factory.py +++ b/src/sage/symbolic/function_factory.py @@ -150,7 +150,7 @@ def unpickle_function(name, nargs, latex_name, conversions, evalf_params_first, return function_factory(*args) -def function(s, **kwds) -> Union[SymbolicFunction, list[SymbolicFunction]]: +def function(s, **kwds) -> SymbolicFunction | list[SymbolicFunction]: r""" Create a formal symbolic function with the name *s*. diff --git a/src/sage/symbolic/operators.py b/src/sage/symbolic/operators.py index 4e1debed2b7..fcada6cdcdf 100644 --- a/src/sage/symbolic/operators.py +++ b/src/sage/symbolic/operators.py @@ -72,7 +72,7 @@ def mul_vararg(first, *rest): operator.ge: '>='} -class FDerivativeOperator(): +class FDerivativeOperator: r""" Function derivative operators. @@ -201,7 +201,7 @@ def parameter_set(self): return self._parameter_set -class DerivativeOperator(): +class DerivativeOperator: """ Derivative operator. @@ -226,7 +226,7 @@ class DerivativeOperator(): sage: D[0, 1](f)(x, x^2) D[0, 1](f)(x, x^2) """ - class DerivativeOperatorWithParameters(): + class DerivativeOperatorWithParameters: def __init__(self, parameter_set): self._parameter_set = parameter_set diff --git a/src/sage/tensor/modules/finite_rank_free_module.py b/src/sage/tensor/modules/finite_rank_free_module.py index 3ef4c119b81..9a4e44f0f12 100644 --- a/src/sage/tensor/modules/finite_rank_free_module.py +++ b/src/sage/tensor/modules/finite_rank_free_module.py @@ -2717,7 +2717,7 @@ def dual(self): """ return self.dual_exterior_power(1) - def irange(self, start: Optional[int] = None) -> Generator[int, None, None]: + def irange(self, start: int | None = None) -> Generator[int, None, None]: r""" Single index generator, labelling the elements of a basis of ``self``. diff --git a/src/sage/tensor/modules/free_module_element.py b/src/sage/tensor/modules/free_module_element.py index 2f783c57eb5..4b49dcab975 100644 --- a/src/sage/tensor/modules/free_module_element.py +++ b/src/sage/tensor/modules/free_module_element.py @@ -196,8 +196,8 @@ class FiniteRankFreeModuleElement(AlternatingContrTensor): def __init__( self, fmodule: FiniteRankFreeModule, - name: Optional[str] = None, - latex_name: Optional[str] = None, + name: str | None = None, + latex_name: str | None = None, ): r""" TESTS:: diff --git a/src/sage/topology/simplicial_complex_morphism.py b/src/sage/topology/simplicial_complex_morphism.py index 02fbef2402e..52a2d6e82b4 100644 --- a/src/sage/topology/simplicial_complex_morphism.py +++ b/src/sage/topology/simplicial_complex_morphism.py @@ -555,7 +555,7 @@ def is_injective(self): return False return True - def is_identity(self): + def is_identity(self) -> bool: """ If ``self`` is an identity morphism, returns ``True``. Otherwise, ``False``. @@ -588,18 +588,15 @@ def is_identity(self): """ if self.domain() != self.codomain(): return False - else: - f = {} - for i in self.domain().vertices(): - f[i] = i - if self._vertex_dictionary != f: - return False - else: - return True + + f = {i: i for i in self.domain().vertices()} + return self._vertex_dictionary == f def fiber_product(self, other, rename_vertices=True): """ - Fiber product of ``self`` and ``other``. Both morphisms should have + Fiber product of ``self`` and ``other``. + + Both morphisms should have the same codomain. The method returns a morphism of simplicial complexes, which is the morphism from the space of the fiber product to the codomain. diff --git a/src/sage/typeset/character_art.py b/src/sage/typeset/character_art.py index 66d9d0d5e8d..bc64866ed01 100644 --- a/src/sage/typeset/character_art.py +++ b/src/sage/typeset/character_art.py @@ -301,7 +301,7 @@ def _splitting_points(self, size, offset=0): # We implement a custom iterator instead of repeatedly using # itertools.chain to prepend elements in order to avoid quadratic time # complexity - class PrependIterator(): + class PrependIterator: """ Iterator with support for prepending of elements. """ From a5489f71dadcc82a1f42e06d4a3406cba07b3bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Thu, 17 Oct 2024 08:43:25 +0200 Subject: [PATCH 2/2] fix wrong merge --- src/sage/rings/polynomial/multi_polynomial_element.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sage/rings/polynomial/multi_polynomial_element.py b/src/sage/rings/polynomial/multi_polynomial_element.py index a0d25e1aa94..6c4ec02c1b1 100644 --- a/src/sage/rings/polynomial/multi_polynomial_element.py +++ b/src/sage/rings/polynomial/multi_polynomial_element.py @@ -37,7 +37,7 @@ ....: + (a0*b2 - a1*b3 + a2*b0 + a3*b1)^2 + (a0*b3 + a1*b2 - a2*b1 + a3*b0)^2) True """ -#***************************************************************************** +# **************************************************************************** # # Sage: Open Source Mathematical Software # @@ -54,7 +54,7 @@ # The full text of the GPL is available at: # # https://www.gnu.org/licenses/ -#***************************************************************************** +# **************************************************************************** import operator @@ -74,6 +74,7 @@ from sage.rings.rational_field import QQ from sage.rings.fraction_field import FractionField + class MPolynomial_element(MPolynomial): r""" Generic multivariate polynomial. @@ -1929,7 +1930,7 @@ def _derivative(self, var=None): if index == -1: # var is not a generator; do term-by-term differentiation recursively # var may be, for example, a generator of the base ring - d = {e: x._derivative(var)) + d = {e: x._derivative(var) for e, x in self.monomial_coefficients().items()} d = polydict.PolyDict(d, check=False) d.remove_zeros() @@ -2495,6 +2496,7 @@ def reduce(self, I): p -= plt return r + ############################################################### # Useful for some geometry code. ###############################################################