2323# it under the terms of the GNU General Public License as published by
2424# the Free Software Foundation, either version 2 of the License, or
2525# (at your option) any later version.
26- # http ://www.gnu.org/licenses/
26+ # https ://www.gnu.org/licenses/
2727# ****************************************************************************
2828
29-
29+ from sage . categories . fields import Fields
3030from sage .misc .cachefunc import cached_method
3131from sage .rings .infinity import infinity
32- from sage .rings .puiseux_series_ring_element import PuiseuxSeries
33- from sage .structure .unique_representation import UniqueRepresentation
34- from sage .rings .ring import CommutativeRing
35- from sage .structure .element import parent
3632from sage .rings .laurent_series_ring import LaurentSeriesRing
3733from sage .rings .laurent_series_ring_element import LaurentSeries
3834from sage .rings .power_series_ring import is_PowerSeriesRing
3935from sage .rings .power_series_ring_element import PowerSeries
36+ from sage .rings .puiseux_series_ring_element import PuiseuxSeries
37+ from sage .structure .element import parent
38+ from sage .structure .parent import Parent
39+ from sage .structure .unique_representation import UniqueRepresentation
4040
4141
42- class PuiseuxSeriesRing (UniqueRepresentation , CommutativeRing ):
42+ class PuiseuxSeriesRing (UniqueRepresentation , Parent ):
4343 """
4444 Rings of Puiseux series.
4545
@@ -101,11 +101,14 @@ def __init__(self, laurent_series):
101101 # ring will be R(( x ))
102102 self ._laurent_series_ring = laurent_series
103103
104- CommutativeRing .__init__ (self , base_ring ,
105- names = laurent_series .variable_names (),
106- category = laurent_series .category ())
104+ cat = laurent_series .category ()
105+ if base_ring in Fields ():
106+ cat &= Fields ()
107+ Parent .__init__ (self , base_ring ,
108+ names = laurent_series .variable_names (),
109+ category = cat )
107110
108- def _repr_ (self ):
111+ def _repr_ (self ) -> str :
109112 """
110113 String representation.
111114
@@ -114,8 +117,7 @@ def _repr_(self):
114117 sage: PuiseuxSeriesRing(AA, 'y') # needs sage.rings.number_field
115118 Puiseux Series Ring in y over Algebraic Real Field
116119 """
117- s = "Puiseux Series Ring in {} over {}" .format (self .variable_name (),
118- self .base_ring ())
120+ s = f"Puiseux Series Ring in { self .variable_name ()} over { self .base_ring ()} "
119121 if self .is_sparse ():
120122 s = 'Sparse ' + s
121123 return s
@@ -152,7 +154,7 @@ def change_ring(self, R):
152154 """
153155 return PuiseuxSeriesRing (self ._laurent_series_ring .change_ring (R ))
154156
155- def is_sparse (self ):
157+ def is_sparse (self ) -> bool :
156158 """
157159 Return whether ``self`` is sparse.
158160
@@ -164,7 +166,7 @@ def is_sparse(self):
164166 """
165167 return self .laurent_series_ring ().is_sparse ()
166168
167- def is_dense (self ):
169+ def is_dense (self ) -> bool :
168170 """
169171 Return whether ``self`` is dense.
170172
@@ -176,7 +178,7 @@ def is_dense(self):
176178 """
177179 return self .laurent_series_ring ().is_dense ()
178180
179- def is_field (self , proof = True ):
181+ def is_field (self , proof = True ) -> bool :
180182 r"""
181183 Return whether ``self`` is a field.
182184
@@ -188,7 +190,11 @@ def is_field(self, proof=True):
188190 sage: A = PuiseuxSeriesRing(ZZ, 'y')
189191 sage: A.is_field()
190192 False
191- sage: A.change_ring(QQ).is_field()
193+ sage: A in Fields()
194+ False
195+ sage: B = A.change_ring(QQ); B.is_field()
196+ True
197+ sage: B in Fields()
192198 True
193199 """
194200 return self .base_ring ().is_field (proof = proof )
@@ -199,7 +205,7 @@ def fraction_field(self):
199205
200206 If the base ring is a field, then Puiseux series are already a field.
201207 If the base ring is a domain, then the Puiseux series over its fraction
202- field is returned. Otherwise, raise a `` ValueError` `.
208+ field is returned. Otherwise, raise a :class:` ValueError`.
203209
204210 EXAMPLES::
205211
@@ -218,10 +224,9 @@ def fraction_field(self):
218224 from sage .categories .fields import Fields
219225 if self in Fields ():
220226 return self
221- elif self in IntegralDomains ():
227+ if self in IntegralDomains ():
222228 return PuiseuxSeriesRing (self ._laurent_series_ring .fraction_field ())
223- else :
224- raise ValueError ('must be an integral domain' )
229+ raise ValueError ('must be an integral domain' )
225230
226231 def residue_field (self ):
227232 r"""
@@ -242,7 +247,7 @@ def residue_field(self):
242247 ...
243248 TypeError: the base ring is not a field
244249 """
245- if not self .base_ring (). is_field ():
250+ if self .base_ring () not in Fields ():
246251 raise TypeError ("the base ring is not a field" )
247252 return self .base_ring ()
248253
@@ -264,7 +269,7 @@ def uniformizer(self):
264269 ...
265270 TypeError: the base ring is not a field
266271 """
267- if not self .base_ring (). is_field ():
272+ if self .base_ring () not in Fields ():
268273 raise TypeError ("the base ring is not a field" )
269274 return self .gen ()
270275
@@ -310,7 +315,7 @@ def _element_constructor_(self, x, e=1, prec=infinity):
310315
311316 # 1. x is a Puiseux series belonging to this ring.
312317 # This is short-circuited by the coercion framework.
313- #if isinstance(x, self.element_class) and P is self:
318+ # if isinstance(x, self.element_class) and P is self:
314319 # return x
315320 # 2. x is a Puiseux series but not an element of this ring. the laurent
316321 # part should be coercible to the laurent series ring of self
@@ -400,10 +405,22 @@ def gen(self, n=0):
400405 z
401406 """
402407 if n != 0 :
403- raise IndexError ("generator {} not defined" . format ( n ) )
408+ raise IndexError (f "generator { n } not defined" )
404409 return self .element_class (self , [0 , 1 ], e = 1 )
405410
406- def ngens (self ):
411+ def gens (self ) -> tuple :
412+ """
413+ Return the tuple of generators.
414+
415+ EXAMPLES::
416+
417+ sage: A = PuiseuxSeriesRing(QQ, 'z')
418+ sage: A.gens()
419+ (z,)
420+ """
421+ return (self .gen (),)
422+
423+ def ngens (self ) -> int :
407424 r"""
408425 Return the number of generators of ``self``, namely 1.
409426
0 commit comments