From 2f4c2c1d497dddb9622307962455c97792d1c160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Wed, 11 Sep 2024 08:42:08 +0200 Subject: [PATCH] fixing some mypy suggestions in algebras and abvar --- src/sage/algebras/cluster_algebra.py | 7 +++--- src/sage/algebras/iwahori_hecke_algebra.py | 2 +- .../lie_conformal_algebras/examples.py | 17 +++----------- src/sage/modular/abvar/abvar.py | 22 +++++-------------- .../modular/abvar/abvar_ambient_jacobian.py | 2 +- src/sage/modular/abvar/abvar_newform.py | 2 +- src/sage/modular/abvar/constructor.py | 2 +- src/sage/modular/abvar/homspace.py | 2 +- 8 files changed, 18 insertions(+), 38 deletions(-) diff --git a/src/sage/algebras/cluster_algebra.py b/src/sage/algebras/cluster_algebra.py index 042b9365ecb..a101064eb0e 100644 --- a/src/sage/algebras/cluster_algebra.py +++ b/src/sage/algebras/cluster_algebra.py @@ -355,6 +355,7 @@ # **************************************************************************** from copy import copy +from typing import Any from sage.arith.misc import binomial from sage.categories.homset import Hom @@ -562,7 +563,7 @@ def homogeneous_components(self) -> dict: """ deg_matrix = block_matrix([[identity_matrix(self.parent().rank()), -self.parent().b_matrix()]]) - components = {} + components: dict[tuple, Any] = {} x = self.lift() monomials = x.monomials() for m in monomials: @@ -1432,11 +1433,11 @@ def _repr_(self) -> str: and coefficients y0, y1 over Integer Ring """ var_names = self.initial_cluster_variable_names() - var_names = (" " if len(var_names) == 1 else "s ") + ", ".join(var_names) + var_names_str = (" " if len(var_names) == 1 else "s ") + ", ".join(var_names) coeff_names = self.coefficient_names() coeff_prefix = " and" + (" " if len(coeff_names) > 0 else " no ") + "coefficient" coeff = coeff_prefix + (" " if len(coeff_names) == 1 else "s ") + ", ".join(coeff_names) + (" " if len(coeff_names) > 0 else "") - return "A Cluster Algebra with cluster variable" + var_names + coeff + "over " + repr(self.scalars()) + return "A Cluster Algebra with cluster variable" + var_names_str + coeff + "over " + repr(self.scalars()) def _an_element_(self): r""" diff --git a/src/sage/algebras/iwahori_hecke_algebra.py b/src/sage/algebras/iwahori_hecke_algebra.py index b4dc71825af..48796fbd605 100644 --- a/src/sage/algebras/iwahori_hecke_algebra.py +++ b/src/sage/algebras/iwahori_hecke_algebra.py @@ -1255,7 +1255,7 @@ def __init__(self, algebra, prefix=None): # This **must** match the name of the class in order for # specialize_to() to work - _basis_name = None + _basis_name = 'B' def _repr_term(self, t): r""" diff --git a/src/sage/algebras/lie_conformal_algebras/examples.py b/src/sage/algebras/lie_conformal_algebras/examples.py index 3d520e449db..1db194445be 100644 --- a/src/sage/algebras/lie_conformal_algebras/examples.py +++ b/src/sage/algebras/lie_conformal_algebras/examples.py @@ -20,15 +20,15 @@ - Reimundo Heluani (2020-06-15): Initial implementation. """ -#****************************************************************************** +# ***************************************************************************** # Copyright (C) 2020 Reimundo Heluani # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from .abelian_lie_conformal_algebra import AbelianLieConformalAlgebra as Abelian from .affine_lie_conformal_algebra import AffineLieConformalAlgebra as Affine @@ -40,14 +40,3 @@ from .neveu_schwarz_lie_conformal_algebra import NeveuSchwarzLieConformalAlgebra as NeveuSchwarz from .virasoro_lie_conformal_algebra import VirasoroLieConformalAlgebra as Virasoro from .weyl_lie_conformal_algebra import WeylLieConformalAlgebra as Weyl - -assert Abelian -assert Affine -assert BosonicGhosts -assert FermionicGhosts -assert FreeBosons -assert FreeFermions -assert N2 -assert NeveuSchwarz -assert Virasoro -assert Weyl diff --git a/src/sage/modular/abvar/abvar.py b/src/sage/modular/abvar/abvar.py index b3d8f3492b0..80f1fd3e7c4 100644 --- a/src/sage/modular/abvar/abvar.py +++ b/src/sage/modular/abvar/abvar.py @@ -41,6 +41,7 @@ from sage.categories.modular_abelian_varieties import ModularAbelianVarieties from sage.matrix.constructor import matrix from sage.matrix.special import block_diagonal_matrix, identity_matrix +from sage.misc.cachefunc import cached_method from sage.misc.lazy_import import lazy_import from sage.misc.misc_c import prod from sage.modular.arithgroup.congroup_gamma0 import Gamma0_class @@ -69,8 +70,7 @@ ['cremona_letter_code', 'CremonaDatabase']) -from . import homspace -from . import lseries +from sage.modular.abvar import homspace, lseries from .morphism import HeckeOperator, Morphism, DegeneracyMap from .torsion_subgroup import RationalTorsionSubgroup, QQbarTorsionSubgroup from .finite_subgroup import (FiniteSubgroup_lattice, FiniteSubgroup, @@ -1728,6 +1728,7 @@ def ambient_morphism(self): self.__ambient_morphism = phi return phi + @cached_method def is_ambient(self) -> bool: """ Return ``True`` if ``self`` equals the ambient product Jacobian. @@ -1746,13 +1747,8 @@ def is_ambient(self) -> bool: sage: (A+B+C).is_ambient() True """ - try: - return self.__is_ambient - except AttributeError: - pass L = self.lattice() - self.__is_ambient = (self.lattice() == ZZ**L.degree()) - return self.__is_ambient + return self.lattice() == ZZ**L.degree() def dimension(self): """ @@ -1890,6 +1886,7 @@ def sturm_bound(self): self.__sturm_bound = B return B + @cached_method def is_hecke_stable(self) -> bool: """ Return ``True`` if ``self`` is stable under the Hecke operators of its @@ -1908,11 +1905,6 @@ def is_hecke_stable(self) -> bool: sage: (J0(33)[0] + J0(33)[1]).is_hecke_stable() True """ - try: - return self._is_hecke_stable - except AttributeError: - pass - # b = self.modular_symbols().sturm_bound() b = max([m.sturm_bound() for m in self._ambient_modular_symbols_spaces()]) @@ -1924,10 +1916,8 @@ def is_hecke_stable(self) -> bool: Tn_matrix = J.hecke_operator(n).matrix() for v in B: if v * Tn_matrix not in L: - self._is_hecke_stable = False return False - self._is_hecke_stable = True return True def is_subvariety(self, other) -> bool: @@ -2467,7 +2457,7 @@ def homology(self, base_ring=ZZ): sage: J0(389).homology(ZZ) Integral Homology of Abelian variety J0(389) of dimension 32 """ - from . import homology + from sage.modular.abvar import homology try: return self._homology[base_ring] except AttributeError: diff --git a/src/sage/modular/abvar/abvar_ambient_jacobian.py b/src/sage/modular/abvar/abvar_ambient_jacobian.py index a25d82d5b8c..1a7c1e82370 100644 --- a/src/sage/modular/abvar/abvar_ambient_jacobian.py +++ b/src/sage/modular/abvar/abvar_ambient_jacobian.py @@ -20,7 +20,7 @@ from sage.modular.modsym.modsym import ModularSymbols from sage.modular.modform.constructor import Newforms from sage.modular.arithgroup.all import Gamma0_class, Gamma1_class -from . import morphism +from sage.modular.abvar import morphism _cache = {} diff --git a/src/sage/modular/abvar/abvar_newform.py b/src/sage/modular/abvar/abvar_newform.py index 1159de73894..9568e5481cc 100644 --- a/src/sage/modular/abvar/abvar_newform.py +++ b/src/sage/modular/abvar/abvar_newform.py @@ -22,7 +22,7 @@ from sage.modular.arithgroup.all import Gamma0_class, Gamma1_class, GammaH_class from .abvar import ModularAbelianVariety_modsym_abstract -from . import homspace +from sage.modular.abvar import homspace lazy_import('sage.databases.cremona', 'cremona_letter_code') diff --git a/src/sage/modular/abvar/constructor.py b/src/sage/modular/abvar/constructor.py index a39f7819393..78e160edfe6 100644 --- a/src/sage/modular/abvar/constructor.py +++ b/src/sage/modular/abvar/constructor.py @@ -19,7 +19,7 @@ from sage.modular.modsym.space import ModularSymbolsSpace from .abvar_newform import ModularAbelianVariety_newform import sage.modular.modform.element -from . import abvar +from sage.modular.abvar import abvar _cache = {} diff --git a/src/sage/modular/abvar/homspace.py b/src/sage/modular/abvar/homspace.py index 2333bbacd00..30ad76f3601 100644 --- a/src/sage/modular/abvar/homspace.py +++ b/src/sage/modular/abvar/homspace.py @@ -187,7 +187,7 @@ from sage.misc.lazy_attribute import lazy_attribute -from . import morphism +from sage.modular.abvar import morphism from sage.rings.infinity import Infinity