Skip to content

Commit abff47f

Browse files
author
Release Manager
committed
sagemathgh-41144: some type annotations in algebras,coding,graphs mostly about adding type annotations like `def __contains__(self, x) -> bool:` and `def __init__(self) -> None:` and a few similar things ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: sagemath#41144 Reported by: Frédéric Chapoton Reviewer(s):
2 parents 495e785 + ab8f9c6 commit abff47f

File tree

14 files changed

+69
-65
lines changed

14 files changed

+69
-65
lines changed

src/sage/algebras/clifford_algebra.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class CliffordAlgebraIndices(UniqueRepresentation, Parent):
5151
A facade parent for the indices of Clifford algebra.
5252
Users should not create instances of this class directly.
5353
"""
54-
def __init__(self, Qdim, degree=None):
54+
def __init__(self, Qdim, degree=None) -> None:
5555
r"""
5656
Initialize ``self``.
5757
@@ -271,7 +271,7 @@ def __iter__(self):
271271
yield FrozenBitset(C)
272272
k += 1
273273

274-
def __contains__(self, elt):
274+
def __contains__(self, elt) -> bool:
275275
r"""
276276
Check containment of ``elt`` in ``self``.
277277
@@ -503,7 +503,7 @@ def __classcall_private__(cls, Q, names=None):
503503
raise ValueError("the number of variables does not match the number of generators")
504504
return super().__classcall__(cls, Q, names)
505505

506-
def __init__(self, Q, names, category=None):
506+
def __init__(self, Q, names, category=None) -> None:
507507
r"""
508508
Initialize ``self``.
509509
@@ -1463,7 +1463,7 @@ def __classcall_private__(cls, R, names=None, n=None):
14631463
raise ValueError("the number of variables does not match the number of generators")
14641464
return super().__classcall__(cls, R, names)
14651465

1466-
def __init__(self, R, names):
1466+
def __init__(self, R, names) -> None:
14671467
"""
14681468
Initialize ``self``.
14691469
@@ -2124,7 +2124,7 @@ def __classcall__(cls, E, s_coeff):
21242124
from sage.sets.family import Family
21252125
return super().__classcall__(cls, E, Family(d))
21262126

2127-
def __init__(self, E, s_coeff):
2127+
def __init__(self, E, s_coeff) -> None:
21282128
"""
21292129
Initialize ``self``.
21302130
@@ -2538,7 +2538,7 @@ class ExteriorAlgebraCoboundary(ExteriorAlgebraDifferential):
25382538
25392539
- :wikipedia:`Exterior_algebra#Differential_geometry`
25402540
"""
2541-
def __init__(self, E, s_coeff):
2541+
def __init__(self, E, s_coeff) -> None:
25422542
"""
25432543
Initialize ``self``.
25442544
@@ -2733,7 +2733,7 @@ class ExteriorAlgebraIdeal(Ideal_nc):
27332733
sage: xbar * ybar
27342734
0
27352735
"""
2736-
def __init__(self, ring, gens, coerce=True, side='twosided'):
2736+
def __init__(self, ring, gens, coerce=True, side='twosided') -> None:
27372737
"""
27382738
Initialize ``self``.
27392739
@@ -2815,7 +2815,7 @@ def _contains_(self, f):
28152815
"""
28162816
return not self.reduce(f)
28172817

2818-
def __richcmp__(self, other, op):
2818+
def __richcmp__(self, other, op) -> bool:
28192819
"""
28202820
Compare ``self`` and ``other``.
28212821

src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_ideal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class FiniteDimensionalAlgebraIdeal(Ideal_generic):
4747
sage: A.ideal(A([0,1]))
4848
Ideal (e1) of Finite-dimensional algebra of degree 2 over Finite Field of size 3
4949
"""
50-
def __init__(self, A, gens=None, given_by_matrix=False):
50+
def __init__(self, A, gens=None, given_by_matrix=False) -> bool:
5151
"""
5252
EXAMPLES::
5353
@@ -138,7 +138,7 @@ def _richcmp_(self, other, op):
138138
elif op == op_GE or op == op_GT:
139139
return other.vector_space().is_subspace(self.vector_space())
140140

141-
def __contains__(self, elt):
141+
def __contains__(self, elt) -> bool:
142142
"""
143143
EXAMPLES::
144144

src/sage/algebras/letterplace/letterplace_ideal.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class LetterplaceIdeal(Ideal_nc):
155155
sage: (z*I.0-x*y*z).normal_form(I)
156156
-y*x*z + z*z
157157
"""
158-
def __init__(self, ring, gens, coerce=True, side='twosided'):
158+
def __init__(self, ring, gens, coerce=True, side='twosided') -> None:
159159
"""
160160
INPUT:
161161

@@ -334,7 +334,7 @@ class LetterplaceIdeal(Ideal_nc):
334334
self.__GB.__uptodeg = degbound
335335
return self.__GB
336336

337-
def __contains__(self, x):
337+
def __contains__(self, x) -> bool:
338338
"""
339339
The containment test is based on a normal form computation.
340340

src/sage/algebras/lie_algebras/affine_lie_algebra.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __classcall_private__(cls, arg0, cartan_type=None, kac_moody=True):
106106
return UntwistedAffineLieAlgebra(g, kac_moody=kac_moody)
107107
return TwistedAffineLieAlgebra(arg0, cartan_type, kac_moody=kac_moody)
108108

109-
def __init__(self, g, cartan_type, names, kac_moody):
109+
def __init__(self, g, cartan_type, names, kac_moody) -> None:
110110
"""
111111
Initialize ``self``.
112112
@@ -578,7 +578,7 @@ class UntwistedAffineLieAlgebra(AffineLieAlgebra):
578578
sage: D.d()
579579
0
580580
"""
581-
def __init__(self, g, kac_moody):
581+
def __init__(self, g, kac_moody) -> None:
582582
"""
583583
Initialize ``self``.
584584
@@ -671,7 +671,7 @@ class TwistedAffineLieAlgebra(AffineLieAlgebra):
671671
weights in this representation with the roots of type `B_n` and
672672
the double all of its short roots.
673673
"""
674-
def __init__(self, R, cartan_type, kac_moody):
674+
def __init__(self, R, cartan_type, kac_moody) -> None:
675675
"""
676676
Initialize ``self``.
677677
@@ -1107,7 +1107,7 @@ def __classcall_private__(cls, cartan_type):
11071107
raise ValueError("the Cartan type must be a twisted affine type")
11081108
return super().__classcall__(cls, cartan_type)
11091109

1110-
def __init__(self, cartan_type):
1110+
def __init__(self, cartan_type) -> None:
11111111
"""
11121112
Initialize ``self``.
11131113
@@ -1141,7 +1141,7 @@ def __init__(self, cartan_type):
11411141
from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets
11421142
super().__init__(facade=facade, category=InfiniteEnumeratedSets())
11431143

1144-
def __contains__(self, x):
1144+
def __contains__(self, x) -> bool:
11451145
"""
11461146
Return if ``x`` is contained in ``self``.
11471147

src/sage/algebras/lie_algebras/bgg_dual_module.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class BGGDualModule(CombinatorialFreeModule):
100100
101101
- [Humphreys08]_
102102
"""
103-
def __init__(self, module):
103+
def __init__(self, module) -> None:
104104
r"""
105105
Initialize ``self``.
106106
@@ -458,7 +458,7 @@ def __classcall__(cls, simple, prefix='f', **kwds):
458458
"""
459459
return super(IndexedMonoid, cls).__classcall__(cls, simple, prefix=prefix, **kwds)
460460

461-
def __init__(self, simple, prefix, category=None, **kwds):
461+
def __init__(self, simple, prefix, category=None, **kwds) -> None:
462462
r"""
463463
Initialize ``self``.
464464
@@ -591,7 +591,7 @@ def weight_space_basis(self, mu):
591591
self._construct_next_level()
592592
return self._weight_space_bases.get(mu, [])
593593

594-
def __contains__(self, m):
594+
def __contains__(self, m) -> bool:
595595
r"""
596596
Check if ``m`` is contained in ``self``.
597597
@@ -815,7 +815,7 @@ def __classcall_private__(cls, g, weight, *args, **kwds):
815815
return FiniteDimensionalSimpleModule(g, weight, *args, **kwds)
816816
return super().__classcall__(cls, g, weight, *args, **kwds)
817817

818-
def __init__(self, g, weight, prefix='f', basis_key=None, **kwds):
818+
def __init__(self, g, weight, prefix='f', basis_key=None, **kwds) -> None:
819819
r"""
820820
Initialize ``self``.
821821

src/sage/algebras/lie_algebras/subalgebra.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ def __classcall_private__(cls, ambient, gens, ideal_of=None,
260260
return super().__classcall__(cls, ambient, gens, ideal_of,
261261
order, category)
262262

263-
def __init__(self, ambient, gens, ideal_of, order=None, category=None):
263+
def __init__(self, ambient, gens, ideal_of,
264+
order=None, category=None) -> None:
264265
r"""
265266
Initialize ``self``.
266267
@@ -302,7 +303,7 @@ def __init__(self, ambient, gens, ideal_of, order=None, category=None):
302303
f = SetMorphism(H, self.lift)
303304
ambient.register_coercion(f)
304305

305-
def __contains__(self, x):
306+
def __contains__(self, x) -> bool:
306307
r"""
307308
Return ``True`` if ``x`` is an element of ``self``.
308309
@@ -338,7 +339,8 @@ def __getitem__(self, x):
338339
If `x` is a pair `(a, b)`, return the Lie bracket `[a, b]`.
339340
Otherwise try to return the `x`-th element of ``self``.
340341
341-
This replicates the convenience syntax for Lie brackets of Lie algebras.
342+
This replicates the convenience syntax for Lie brackets
343+
of Lie algebras.
342344
343345
EXAMPLES::
344346

src/sage/algebras/quatalg/quaternion_algebra.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ class QuaternionAlgebra_ab(QuaternionAlgebra_abstract):
823823
sage: QuaternionAlgebra(QQ, -7, -21) # indirect doctest
824824
Quaternion Algebra (-7, -21) with base ring Rational Field
825825
"""
826-
def __init__(self, base_ring, a, b, names='i,j,k'):
826+
def __init__(self, base_ring, a, b, names='i,j,k') -> None:
827827
"""
828828
Create the quaternion algebra with `i^2 = a`, `j^2 = b`, and
829829
`ij = -ji = k`.
@@ -1234,7 +1234,7 @@ def invariants(self):
12341234
"""
12351235
return self._a, self._b
12361236

1237-
def __eq__(self, other):
1237+
def __eq__(self, other) -> bool:
12381238
"""
12391239
Compare ``self`` and ``other``.
12401240
@@ -1250,7 +1250,7 @@ def __eq__(self, other):
12501250
return (self.base_ring() == other.base_ring() and
12511251
(self._a, self._b) == (other._a, other._b))
12521252

1253-
def __ne__(self, other):
1253+
def __ne__(self, other) -> bool:
12541254
"""
12551255
Compare ``self`` and ``other``.
12561256
@@ -1263,7 +1263,7 @@ def __ne__(self, other):
12631263
"""
12641264
return not self.__eq__(other)
12651265

1266-
def __hash__(self):
1266+
def __hash__(self) -> int:
12671267
"""
12681268
Compute the hash of ``self``.
12691269
@@ -1985,7 +1985,7 @@ class QuaternionOrder(Parent):
19851985
sage: type(QuaternionAlgebra(-1,-7).maximal_order())
19861986
<class 'sage.algebras.quatalg.quaternion_algebra.QuaternionOrder_with_category'>
19871987
"""
1988-
def __init__(self, A, basis, check=True):
1988+
def __init__(self, A, basis, check=True) -> None:
19891989
"""
19901990
INPUT:
19911991
@@ -2186,7 +2186,7 @@ def gen(self, n):
21862186
"""
21872187
return self.__basis[n]
21882188

2189-
def __richcmp__(self, other, op):
2189+
def __richcmp__(self, other, op) -> bool:
21902190
"""
21912191
Compare this quaternion order to ``other``.
21922192
@@ -2239,7 +2239,7 @@ def __richcmp__(self, other, op):
22392239
return op == op_NE
22402240
return richcmp(self.unit_ideal(), other.unit_ideal(), op)
22412241

2242-
def __hash__(self):
2242+
def __hash__(self) -> int:
22432243
"""
22442244
Compute the hash of ``self``.
22452245
@@ -3013,7 +3013,8 @@ class QuaternionFractionalIdeal_rational(QuaternionFractionalIdeal):
30133013
- ``check`` -- boolean (default: ``True``); if ``False``, do no type
30143014
checking.
30153015
"""
3016-
def __init__(self, Q, basis, left_order=None, right_order=None, check=True):
3016+
def __init__(self, Q, basis, left_order=None,
3017+
right_order=None, check=True) -> None:
30173018
"""
30183019
EXAMPLES::
30193020
@@ -3267,7 +3268,7 @@ def right_order(self):
32673268
self.__right_order = self._compute_order(side='right')
32683269
return self.__right_order
32693270

3270-
def __repr__(self):
3271+
def __repr__(self) -> str:
32713272
"""
32723273
Return string representation of this quaternion fractional ideal.
32733274
@@ -3361,7 +3362,7 @@ def _richcmp_(self, right, op):
33613362
"""
33623363
return self.free_module().__richcmp__(right.free_module(), op)
33633364

3364-
def __hash__(self):
3365+
def __hash__(self) -> int:
33653366
"""
33663367
Return the hash of ``self``.
33673368
@@ -4165,7 +4166,7 @@ def is_principal(self, certificate=False):
41654166
# find an element of minimal norm in self; see [Piz1980]_, Corollary 1.20.
41664167
return True, self.minimal_element()
41674168

4168-
def __contains__(self, x):
4169+
def __contains__(self, x) -> bool:
41694170
"""
41704171
Return whether ``x`` is in ``self``.
41714172

src/sage/algebras/steenrod/steenrod_algebra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,7 @@ def _element_constructor_(self, x):
21292129
return a.change_basis(self.basis_name())
21302130
raise ValueError("element does not lie in this Steenrod algebra")
21312131

2132-
def __contains__(self, x):
2132+
def __contains__(self, x) -> bool:
21332133
r"""
21342134
Return ``True`` if ``self`` contains `x`.
21352135

src/sage/coding/abstract_code.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class AbstractCode(Parent):
203203
"""
204204

205205
def __init__(self, length, default_encoder_name=None,
206-
default_decoder_name=None, metric='Hamming'):
206+
default_decoder_name=None, metric='Hamming') -> None:
207207
r"""
208208
Initialize mandatory parameters that any code shares.
209209
@@ -353,7 +353,7 @@ def __iter__(self):
353353
"""
354354
raise RuntimeError("Please override __iter__ in the implementation of {}".format(self.parent()))
355355

356-
def __contains__(self, c):
356+
def __contains__(self, c) -> bool:
357357
r"""
358358
Return an error message requiring to override ``__contains__`` in ``self``.
359359

0 commit comments

Comments
 (0)