Skip to content

Commit 22f9162

Browse files
author
Release Manager
committed
gh-41148: some typing annotations for contains in rings another one, adding some typing annotations in rings one of the modified files also received a full pep8 cleanup ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #41148 Reported by: Frédéric Chapoton Reviewer(s):
2 parents f546376 + a367968 commit 22f9162

File tree

9 files changed

+85
-81
lines changed

9 files changed

+85
-81
lines changed

src/sage/rings/complex_arb.pyx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField):
360360
"""
361361
return super().__classcall__(cls, precision)
362362

363-
def __init__(self, long precision=53):
363+
def __init__(self, long precision=53) -> None:
364364
r"""
365365
Initialize the complex ball field.
366366

@@ -1399,7 +1399,7 @@ cdef class ComplexBall(RingElement):
13991399
"""
14001400
acb_clear(self.value)
14011401
1402-
def __init__(self, parent, x=None, y=None):
1402+
def __init__(self, parent, x=None, y=None) -> None:
14031403
"""
14041404
Initialize the :class:`ComplexBall`.
14051405

@@ -1529,7 +1529,7 @@ cdef class ComplexBall(RingElement):
15291529
else:
15301530
raise TypeError("unsupported initializer")
15311531
1532-
def __hash__(self):
1532+
def __hash__(self) -> int:
15331533
"""
15341534
TESTS::
15351535

@@ -2333,7 +2333,7 @@ cdef class ComplexBall(RingElement):
23332333
return (arb_is_nonzero(acb_realref(self.value))
23342334
or arb_is_nonzero(acb_imagref(self.value)))
23352335
2336-
def __bool__(self):
2336+
def __bool__(self) -> bool:
23372337
"""
23382338
Return ``True`` iff this complex ball is not the zero ball, i.e. if the
23392339
midpoint and radius of its real and imaginary parts are not all zero.
@@ -2590,7 +2590,7 @@ cdef class ComplexBall(RingElement):
25902590
if _do_sig(prec(self)): sig_off()
25912591
return res
25922592
2593-
def __contains__(self, other):
2593+
def __contains__(self, other) -> bool:
25942594
"""
25952595
Return ``True`` if ``other`` can be verified to be contained in ``self``.
25962596

src/sage/rings/complex_interval.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ cdef class ComplexIntervalFieldElement(FieldElement):
125125
mpfi_init2(self.__re, self._prec)
126126
mpfi_init2(self.__im, self._prec)
127127

128-
def __init__(self, parent, real, imag=None, int base=10):
128+
def __init__(self, parent, real, imag=None, int base=10) -> None:
129129
"""
130130
Initialize a complex number (interval).
131131

@@ -168,7 +168,7 @@ cdef class ComplexIntervalFieldElement(FieldElement):
168168
"""
169169
return self.str(10)
170170

171-
def __hash__(self):
171+
def __hash__(self) -> int:
172172
"""
173173
Return the hash value of ``self``.
174174

@@ -664,7 +664,7 @@ cdef class ComplexIntervalFieldElement(FieldElement):
664664

665665
return center
666666

667-
def __contains__(self, other):
667+
def __contains__(self, other) -> bool:
668668
"""
669669
Test whether ``other`` is totally contained in ``self``.
670670

@@ -1406,7 +1406,7 @@ cdef class ComplexIntervalFieldElement(FieldElement):
14061406
return complex(self.real().n(self._prec),
14071407
self.imag().n(self._prec))
14081408

1409-
def __bool__(self):
1409+
def __bool__(self) -> bool:
14101410
"""
14111411
Return ``True`` if ``self`` is not known to be exactly zero.
14121412

src/sage/rings/ideal.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from sage.categories.rings import Rings
3232
from sage.categories.fields import Fields
3333
from 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
3535
from 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

src/sage/rings/polynomial/laurent_polynomial_ideal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929

3030
class LaurentPolynomialIdeal( Ideal_generic ):
31-
def __init__(self, ring, gens, coerce=True, hint=None):
31+
def __init__(self, ring, gens, coerce=True, hint=None) -> None:
3232
r"""
3333
Create an ideal in a Laurent polynomial ring.
3434
@@ -184,7 +184,7 @@ def _richcmp_(self, right_r, op):
184184
else:
185185
raise ValueError("invalid comparison")
186186

187-
def __contains__(self, f):
187+
def __contains__(self, f) -> bool:
188188
"""
189189
Implement containment testing (in) for Laurent polynomial ideals.
190190

0 commit comments

Comments
 (0)