Skip to content

Commit 6ef8fa1

Browse files
committed
using less isinstance(..., Ring)
1 parent b002b63 commit 6ef8fa1

File tree

8 files changed

+34
-34
lines changed

8 files changed

+34
-34
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: 4 additions & 4 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
@@ -749,9 +749,9 @@ 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
"""
@@ -815,7 +815,7 @@ def __init__(self, A, gens=None, category=None):
815815
homset_cat = category
816816
# Remark: Ring.__init__ will automatically form the join
817817
# of the category of rings and of homset_cat
818-
Ring.__init__(self, A.base_ring(), category=homset_cat.Endsets())
818+
Parent.__init__(self, A.base_ring(), category=homset_cat.Endsets())
819819
Homspace.__init__(self, A, A, cat=homset_cat)
820820
if gens is None:
821821
self._gens = None

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: 2 additions & 2 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,7 +168,7 @@ 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():
171+
if base_ring not in Fields():
172172
raise TypeError("base_ring must be a commutative ring")
173173

174174
if character is None and arithgroup.is_Gamma0(group):

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)