Skip to content

Commit cf3c930

Browse files
author
Release Manager
committed
gh-36922: using less isinstance(..., Ring) in favour of the more categorical `... in Rings()` also fixing a few pep8 details in passing but not too much ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. URL: #36922 Reported by: Frédéric Chapoton Reviewer(s): Frédéric Chapoton, Matthias Köppe, Travis Scrimshaw
2 parents 0c535a3 + 1272029 commit cf3c930

File tree

8 files changed

+52
-57
lines changed

8 files changed

+52
-57
lines changed

src/sage/algebras/affine_nil_temperley_lieb.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from sage.categories.algebras_with_basis import AlgebrasWithBasis
1212
from sage.combinat.root_system.cartan_type import CartanType
1313
from sage.combinat.root_system.weyl_group import WeylGroup
14-
from sage.rings.ring import Ring
14+
from sage.categories.rings import Rings
1515
from sage.rings.integer_ring import ZZ
1616
from sage.combinat.free_module import CombinatorialFreeModule
1717
from sage.misc.cachefunc import cached_method
@@ -54,7 +54,7 @@ def __init__(self, n, R=ZZ, prefix='a'):
5454
sage: A = AffineNilTemperleyLiebTypeA(3, QQ); A
5555
The affine nilTemperley Lieb algebra A3 over the ring Rational Field
5656
"""
57-
if not isinstance(R, Ring):
57+
if R not in Rings():
5858
raise TypeError("argument R must be a ring")
5959
self._cartan_type = CartanType(['A', n - 1, 1])
6060
self._n = n
@@ -234,15 +234,16 @@ def has_no_braid_relation(self, w, i):
234234
if i in w.descents():
235235
return False
236236
s = w.parent().simple_reflections()
237-
wi = w*s[i]
238-
adjacent = [(i-1) % w.parent().n, (i+1) % w.parent().n]
237+
wi = w * s[i]
238+
adjacent = [(i - 1) % w.parent().n,
239+
(i + 1) % w.parent().n]
239240
for j in adjacent:
240241
if j in w.descents():
241242
if j in wi.descents():
242243
return False
243244
else:
244245
return True
245-
return self.has_no_braid_relation(w*s[w.first_descent()],i)
246+
return self.has_no_braid_relation(w * s[w.first_descent()], i)
246247

247248
def _repr_term(self, t, short_display=True):
248249
"""

src/sage/algebras/lie_algebras/lie_algebra.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
from sage.algebras.lie_algebras.lie_algebra_element import (LieAlgebraElementWrapper,
3131
LieAlgebraMatrixWrapper)
3232
from sage.rings.integer_ring import ZZ
33-
from sage.rings.ring import Ring
3433
from sage.matrix.matrix_space import MatrixSpace
3534
from sage.sets.family import Family, AbstractFamily
3635

@@ -419,7 +418,7 @@ def __classcall_private__(cls, R=None, arg0=None, arg1=None, names=None,
419418
raise ValueError("invalid arguments")
420419

421420
def check_assoc(A):
422-
return (isinstance(A, (Ring, MatrixSpace))
421+
return (isinstance(A, MatrixSpace)
423422
or A in Rings()
424423
or A in Algebras(R).Associative())
425424
if arg0 in ZZ or check_assoc(arg1):

src/sage/algebras/splitting_algebra.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,11 @@ def __init__(self, monic_polynomial, names='X', iterate=True, warning=True):
229229
if not base_ring.is_integral_domain():
230230
raise TypeError("base_ring must be an integral domain")
231231
except NotImplementedError:
232-
from sage.rings.ring import Ring
233-
if not isinstance(base_ring, Ring):
234-
raise TypeError("base_ring must be an instance of ring")
232+
from sage.categories.rings import Rings
233+
if base_ring not in Rings():
234+
raise TypeError("base_ring must be a ring")
235235
if warning:
236-
warn('Assuming %s to be an integral domain!' % (base_ring))
236+
warn('Assuming %s to be an integral domain!' % base_ring)
237237

238238
if deg < 1:
239239
raise ValueError("the degree of the polynomial must positive")

src/sage/modular/abvar/homspace.py

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@
183183

184184
from sage.categories.homset import HomsetWithBase
185185
from sage.structure.all import parent
186+
from sage.structure.parent import Parent
186187
from sage.misc.lazy_attribute import lazy_attribute
187188

188189

189190
from . import morphism
190191

191192
from sage.rings.infinity import Infinity
192193

193-
from sage.rings.ring import Ring
194194
from sage.matrix.matrix_space import MatrixSpace
195195
from sage.matrix.constructor import Matrix, identity_matrix
196196
from sage.structure.element import is_Matrix
@@ -482,13 +482,11 @@ def free_module(self):
482482

483483
def gen(self, i=0):
484484
"""
485-
Return i-th generator of self.
485+
Return i-th generator of ``self``.
486486
487487
INPUT:
488488
489-
490-
- ``i`` - an integer
491-
489+
- ``i`` -- an integer
492490
493491
OUTPUT: a morphism
494492
@@ -508,7 +506,7 @@ def gen(self, i=0):
508506

509507
def ngens(self):
510508
"""
511-
Return number of generators of self.
509+
Return number of generators of ``self``.
512510
513511
OUTPUT: integer
514512
@@ -661,10 +659,12 @@ def _calculate_product_gens(self):
661659

662660
def _calculate_simple_gens(self):
663661
"""
664-
Calculate generators for self, where both the domain and codomain
665-
for self are assumed to be simple abelian varieties. The saturation
666-
of the span of these generators in self will be the full space of
667-
homomorphisms from the domain of self to its codomain.
662+
Calculate generators for ``self``, where both the domain and codomain
663+
for ``self`` are assumed to be simple abelian varieties.
664+
665+
The saturation of the span of these generators in ``self``
666+
will be the full space of homomorphisms from the domain of
667+
``self`` to its codomain.
668668
669669
EXAMPLES::
670670
@@ -749,23 +749,21 @@ def _calculate_simple_gens(self):
749749

750750

751751
# NOTE/WARNING/TODO: Below in the __init__, etc. we do *not* check
752-
# that the input gens are give something that spans a sub*ring*, as apposed
752+
# that the input gens are give something that spans a sub*ring*, as opposed
753753
# to just a subgroup.
754-
class EndomorphismSubring(Homspace, Ring):
754+
class EndomorphismSubring(Homspace):
755755

756756
def __init__(self, A, gens=None, category=None):
757757
"""
758758
A subring of the endomorphism ring.
759759
760760
INPUT:
761761
762+
- ``A`` -- an abelian variety
762763
763-
- ``A`` - an abelian variety
764-
765-
- ``gens`` - (default: None); optional; if given
764+
- ``gens`` -- (default: ``None``); optional; if given
766765
should be a tuple of the generators as matrices
767766
768-
769767
EXAMPLES::
770768
771769
sage: J0(23).endomorphism_ring()
@@ -808,14 +806,13 @@ def __init__(self, A, gens=None, category=None):
808806
self._A = A
809807

810808
# Initialise self with the correct category.
811-
# We need to initialise it as a ring first
812809
if category is None:
813810
homset_cat = A.category()
814811
else:
815812
homset_cat = category
816-
# Remark: Ring.__init__ will automatically form the join
813+
# Remark: Parent.__init__ will automatically form the join
817814
# of the category of rings and of homset_cat
818-
Ring.__init__(self, A.base_ring(), category=homset_cat.Endsets())
815+
Parent.__init__(self, A.base_ring(), category=homset_cat.Endsets())
819816
Homspace.__init__(self, A, A, cat=homset_cat)
820817
if gens is None:
821818
self._gens = None
@@ -825,7 +822,7 @@ def __init__(self, A, gens=None, category=None):
825822

826823
def _repr_(self):
827824
"""
828-
Return the string representation of self.
825+
Return the string representation of ``self``.
829826
830827
EXAMPLES::
831828
@@ -853,18 +850,16 @@ def abelian_variety(self):
853850

854851
def index_in(self, other, check=True):
855852
"""
856-
Return the index of self in other.
853+
Return the index of ``self`` in ``other``.
857854
858855
INPUT:
859856
860-
861-
- ``other`` - another endomorphism subring of the
857+
- ``other`` -- another endomorphism subring of the
862858
same abelian variety
863859
864-
- ``check`` - bool (default: True); whether to do some
860+
- ``check`` -- bool (default: ``True``); whether to do some
865861
type and other consistency checks
866862
867-
868863
EXAMPLES::
869864
870865
sage: R = J0(33).endomorphism_ring()

src/sage/modular/modform/space.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
from sage.rings.power_series_ring import PowerSeriesRing
7373
from sage.rings.power_series_ring_element import is_PowerSeries
7474
from sage.rings.rational_field import QQ
75-
from sage.rings.ring import Ring
75+
from sage.categories.rings import Rings
7676

7777
from sage.structure.all import Sequence
7878
from sage.structure.richcmp import (richcmp_method, richcmp, rich_to_bool,
@@ -145,7 +145,7 @@ def __init__(self, group, weight, character, base_ring, category=None):
145145
weight = Integer(weight)
146146
if not ((character is None) or isinstance(character, dirichlet.DirichletCharacter)):
147147
raise TypeError("character must be a Dirichlet character")
148-
if not isinstance(base_ring, Ring):
148+
if base_ring not in Rings():
149149
raise TypeError("base_ring must be a ring")
150150
self.__sturm_bound = None
151151
self.__weight, self.__group, self.__character = weight, group, character
@@ -608,7 +608,7 @@ def integral_basis(self):
608608
pr = W.degree()
609609
B = self.q_integral_basis(pr)
610610
I = [self.linear_combination_of_basis(
611-
W.coordinates(f.padded_list(pr))) for f in B]
611+
W.coordinates(f.padded_list(pr))) for f in B]
612612
return Sequence(I, cr=True, immutable=True)
613613

614614
@cached_method
@@ -688,7 +688,7 @@ def q_expansion_basis(self, prec=None):
688688
]
689689
"""
690690
if prec is None:
691-
try: # don't care about precision -- just must be big enough to determine forms
691+
try: # don't care about precision -- just must be big enough to determine forms
692692
return self.__q_expansion_basis[1]
693693
except AttributeError:
694694
pass
@@ -697,8 +697,8 @@ def q_expansion_basis(self, prec=None):
697697
prec = Integer(self.__normalize_prec(prec))
698698

699699
if prec == 0:
700-
z = self._q_expansion_ring()(0,prec)
701-
return Sequence([z]*int(self.dimension()), immutable=True, cr=True)
700+
z = self._q_expansion_ring()(0, prec)
701+
return Sequence([z] * int(self.dimension()), immutable=True, cr=True)
702702
elif prec != -1:
703703
try:
704704
current_prec, B = self.__q_expansion_basis
@@ -710,7 +710,7 @@ def q_expansion_basis(self, prec=None):
710710
pass
711711

712712
d = self.dimension()
713-
current_prec = max(prec, self.prec(), int(1.2*d) + 3) # +3 for luck.
713+
current_prec = max(prec, self.prec(), int(1.2 * d) + 3) # +3 for luck.
714714
tries = 0
715715
while True:
716716
B = [f for f in self._compute_q_expansion_basis(current_prec) if f != 0]
@@ -769,8 +769,8 @@ def q_echelon_basis(self, prec=None):
769769
"""
770770
prec = self.__normalize_prec(prec)
771771
if prec == 0:
772-
z = self._q_expansion_ring()(0,0)
773-
return Sequence([z]*int(self.dimension()), cr=True)
772+
z = self._q_expansion_ring()(0, 0)
773+
return Sequence([z] * int(self.dimension()), cr=True)
774774
try:
775775
current_prec, B = self.__q_echelon_basis
776776
except AttributeError:
@@ -789,7 +789,7 @@ def q_echelon_basis(self, prec=None):
789789
T = self._q_expansion_ring()
790790
S = [T(f.list(), prec) for f in C.basis()]
791791
for _ in range(self.dimension() - len(S)):
792-
S.append(T(0,prec))
792+
S.append(T(0, prec))
793793
S = Sequence(S, immutable=True, cr=True)
794794
self.__q_echelon_basis = (prec, S)
795795
return S
@@ -818,8 +818,8 @@ def q_integral_basis(self, prec=None):
818818
prec = self.__normalize_prec(prec)
819819
R = PowerSeriesRing(ZZ, name=defaults.DEFAULT_VARIABLE)
820820
if prec == 0:
821-
z = R(0,prec)
822-
return Sequence([z]*int(self.dimension()), cr=True)
821+
z = R(0, prec)
822+
return Sequence([z] * int(self.dimension()), cr=True)
823823
try:
824824
current_prec, B = self.__q_integral_basis
825825
except AttributeError:

src/sage/modular/modsym/ambient.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class ``ModularSymbolsAmbient``, derived from
9494
from sage.rings.integer_ring import ZZ
9595
from sage.rings.polynomial.multi_polynomial import MPolynomial
9696
from sage.rings.rational_field import QQ
97-
from sage.rings.ring import Ring
97+
from sage.categories.fields import Fields
9898
from sage.structure.factorization import Factorization
9999
from sage.structure.formal_sum import FormalSum
100100

@@ -168,8 +168,8 @@ def __init__(self, group, weight, sign, base_ring,
168168
raise TypeError("group must be a congruence subgroup")
169169

170170
sign = int(sign)
171-
if not isinstance(base_ring, Ring) and base_ring.is_field():
172-
raise TypeError("base_ring must be a commutative ring")
171+
if base_ring not in Fields():
172+
raise TypeError("base_ring must be a field")
173173

174174
if character is None and arithgroup.is_Gamma0(group):
175175
character = TrivialCharacter(group.level(), base_ring)
@@ -2983,7 +2983,7 @@ def _compute_hecke_matrix_prime(self, p, rows=None):
29832983
self._hecke_matrices = {}
29842984
except KeyError:
29852985
pass
2986-
tm = verbose("Computing Hecke operator T_%s" % p)
2986+
tm = verbose(f"Computing Hecke operator T_{p}")
29872987

29882988
H = heilbronn.HeilbronnCremona(p)
29892989
# H = heilbronn.HeilbronnMerel(p)

src/sage/modular/modsym/boundary.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
from sage.modular.modsym.manin_symbol import ManinSymbol
103103

104104
from sage.rings.rational_field import Q as QQ
105-
from sage.rings.ring import Ring
105+
from sage.categories.rings import Rings
106106

107107
from . import element
108108

@@ -320,7 +320,7 @@ def __init__(self,
320320
if not arithgroup.is_CongruenceSubgroup(group):
321321
raise TypeError("group must be a congruence subgroup")
322322
sign = int(sign)
323-
if not isinstance(base_ring, Ring):
323+
if base_ring not in Rings().Commutative():
324324
raise TypeError("base_ring must be a commutative ring")
325325
if character is None and arithgroup.is_Gamma0(group):
326326
character = dirichlet.TrivialCharacter(group.level(), base_ring)

src/sage/modular/modsym/relation_matrix.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from sage.misc.verbose import verbose
2929
from sage.modular.modsym.manin_symbol_list import ManinSymbolList
3030
from sage.rings.rational_field import is_RationalField
31-
from sage.rings.ring import Ring
31+
from sage.categories.rings import Rings
3232

3333

3434
SPARSE = True
@@ -551,8 +551,8 @@ def sparse_2term_quotient(rels, n, F):
551551
[(3, -1/3), (3, -1), (3, -1), (3, 1), (5, 1), (5, 1)]
552552
"""
553553
n = int(n)
554-
if not isinstance(F, Ring):
555-
raise TypeError("F must be a ring.")
554+
if F not in Rings():
555+
raise TypeError("F must be a ring")
556556

557557
tm = verbose("Starting sparse 2-term quotient...")
558558
free = list(range(n))

0 commit comments

Comments
 (0)