3131from sage .categories .rings import Rings
3232from sage .categories .fields import Fields
3333from sage .structure .element import MonoidElement
34- from sage .structure .richcmp import rich_to_bool , richcmp , op_NE
34+ from sage .structure .richcmp import rich_to_bool , op_NE
3535from sage .structure .sequence import Sequence
3636
3737
@@ -253,7 +253,7 @@ class Ideal_generic(MonoidElement):
253253
254254 See :func:`Ideal()`.
255255 """
256- def __init__ (self , ring , gens , coerce = True , ** kwds ):
256+ def __init__ (self , ring , gens , coerce = True , ** kwds ) -> None :
257257 """
258258 Initialize this ideal.
259259
@@ -318,7 +318,7 @@ def _repr_short(self):
318318 s = repr (x )
319319 if '\n ' in s :
320320 has_return = True
321- s = s .replace ('\n ' ,'\n ' )
321+ s = s .replace ('\n ' , '\n ' )
322322 L .append (s )
323323 if has_return :
324324 return '\n (\n %s\n )\n ' % (',\n \n ' .join (L ))
@@ -395,7 +395,7 @@ def _richcmp_(self, other, op):
395395 return rich_to_bool (op , + 1 )
396396 raise NotImplementedError (f'ideal comparison in { self .ring ()} is not implemented' )
397397
398- def __contains__ (self , x ):
398+ def __contains__ (self , x ) -> bool :
399399 """
400400 Check if ``x`` is in ``self``.
401401
@@ -439,7 +439,7 @@ def _contains_(self, x):
439439 """
440440 raise NotImplementedError
441441
442- def __bool__ (self ):
442+ def __bool__ (self ) -> bool :
443443 r"""
444444 Return ``True`` if this ideal is not `(0)`.
445445
@@ -1081,7 +1081,7 @@ def __mul__(self, other):
10811081 try :
10821082 if self .ring ().has_coerce_map_from (other ):
10831083 return self
1084- except (TypeError ,ArithmeticError ,ValueError ):
1084+ except (TypeError , ArithmeticError , ValueError ):
10851085 pass
10861086 other = self .ring ().ideal (other )
10871087 return self ._mul_ (other )
@@ -1107,7 +1107,8 @@ def _mul_(self, other):
11071107 sage: I._mul_(J)
11081108 Ideal (x^3*y, x^2*y^2, x^3*z, x^2*y*z, x^4, x^3*y) of Multivariate Polynomial Ring in x, y, z over Rational Field
11091109 """
1110- return self .ring ().ideal ([z for z in [x * y for x in self .gens () for y in other .gens ()] if z ])
1110+ return self .ring ().ideal ([z for x in self .gens () for y in other .gens ()
1111+ if (z := x * y )])
11111112
11121113 def __rmul__ (self , other ):
11131114 """
@@ -1124,10 +1125,11 @@ def __rmul__(self, other):
11241125 try :
11251126 if self .ring ().has_coerce_map_from (other ):
11261127 return self
1127- except (TypeError ,ArithmeticError ,ValueError ):
1128+ except (TypeError , ArithmeticError , ValueError ):
11281129 pass
11291130 other = self .ring ().ideal (other )
1130- return self .ring ().ideal ([z for z in [y * x for x in self .gens () for y in other .gens ()] if z ])
1131+ return self .ring ().ideal ([z for x in self .gens () for y in other .gens ()
1132+ if (z := y * x )])
11311133
11321134 def norm (self ):
11331135 """
@@ -1284,7 +1286,7 @@ class Ideal_principal(Ideal_generic):
12841286 See :func:`Ideal()`.
12851287 """
12861288 # now Ideal_principal takes a list.
1287- #def __init__(self, ring, gen):
1289+ # def __init__(self, ring, gen):
12881290 # Ideal_generic.__init__(self, ring, [gen])
12891291
12901292 def _repr_ (self ):
@@ -1366,7 +1368,7 @@ def gen(self, i=0):
13661368 raise ValueError (f"i (={ i } ) must be 0" )
13671369 return self .gens ()[0 ]
13681370
1369- def __contains__ (self , x ):
1371+ def __contains__ (self , x ) -> bool :
13701372 """
13711373 Return ``True`` if ``x`` is in ``self``.
13721374
@@ -1388,7 +1390,7 @@ def __contains__(self, x):
13881390 except NotImplementedError :
13891391 return self ._contains_ (self .ring ()(x ))
13901392
1391- def __hash__ (self ):
1393+ def __hash__ (self ) -> int :
13921394 r"""
13931395 Very stupid constant hash function!
13941396
@@ -1622,10 +1624,10 @@ def is_prime(self):
16221624 sage: RR.ideal(7).is_prime()
16231625 False
16241626 """
1625- if self .is_zero (): # PIDs are integral domains by definition
1627+ if self .is_zero (): # PIDs are integral domains by definition
16261628 return True
16271629 g = self .gen ()
1628- if g .is_one (): # The ideal (1) is never prime
1630+ if g .is_one (): # The ideal (1) is never prime
16291631 return False
16301632 if hasattr (g , 'is_irreducible' ):
16311633 return g .is_irreducible ()
@@ -1819,7 +1821,7 @@ def Cyclic(R, n=None, homog=False, singular=None):
18191821 if not homog :
18201822 I = singular .cyclic (n )
18211823 else :
1822- I = singular .cyclic (n ).homog (R2 .gen (n - 1 ))
1824+ I = singular .cyclic (n ).homog (R2 .gen (n - 1 ))
18231825 return R2 .ideal (I ).change_ring (R )
18241826
18251827
@@ -1870,7 +1872,7 @@ def Katsura(R, n=None, homog=False, singular=None):
18701872 if not homog :
18711873 I = singular .katsura (n )
18721874 else :
1873- I = singular .katsura (n ).homog (R2 .gen (n - 1 ))
1875+ I = singular .katsura (n ).homog (R2 .gen (n - 1 ))
18741876 return R2 .ideal (I ).change_ring (R )
18751877
18761878
0 commit comments