Skip to content

Commit 366fb98

Browse files
author
Release Manager
committed
gh-40096: use _an_element_ and type annotations in ore_module using `_an_element_` in the modified file ; also adding some typing annotations there ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #40096 Reported by: Frédéric Chapoton Reviewer(s): Edgar Costa
2 parents 8a1fdf6 + 7e2e7a7 commit 366fb98

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/sage/modules/ore_module.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
# ***************************************************************************
181181

182182
import operator
183+
183184
from sage.misc.latex import latex
184185
from sage.misc.latex import latex_variable_name
185186
from sage.structure.sequence import Sequence
@@ -360,7 +361,7 @@ def __classcall_private__(cls, mat, twist, names=None, category=None):
360361
names = normalize_names(names, rank)
361362
return cls.__classcall__(cls, mat, category._ore, names, category)
362363

363-
def __init__(self, mat, ore, names, category):
364+
def __init__(self, mat, ore, names, category) -> None:
364365
r"""
365366
Initialize this Ore module.
366367
@@ -399,7 +400,7 @@ def __init__(self, mat, ore, names, category):
399400
self._quotientModule_class = OreQuotientModule
400401
self._pseudohom = FreeModule_ambient.pseudohom(self, mat, ore, codomain=self)
401402

402-
def _repr_(self):
403+
def _repr_(self) -> str:
403404
r"""
404405
Return a string representation of this Ore module.
405406
@@ -430,7 +431,7 @@ def _repr_(self):
430431
s += "over %s %s" % (self.base_ring(), self._ore._repr_twist())
431432
return s
432433

433-
def _latex_(self):
434+
def _latex_(self) -> str:
434435
r"""
435436
Return a LaTeX representation of this Ore module.
436437
@@ -470,7 +471,7 @@ def _latex_(self):
470471
s += "}"
471472
return s
472473

473-
def _repr_element(self, x):
474+
def _repr_element(self, x) -> str:
474475
r"""
475476
Return a string representation of the element `x` in
476477
this Ore module.
@@ -485,7 +486,7 @@ def _repr_element(self, x):
485486
"""
486487
return FreeModuleElement_generic_dense._repr_(x)
487488

488-
def _latex_element(self, x):
489+
def _latex_element(self, x) -> str:
489490
r"""
490491
Return a LaTeX representation of the element `x` in
491492
this Ore module.
@@ -783,7 +784,7 @@ def matrix(self):
783784
"""
784785
return self._pseudohom.matrix()
785786

786-
def basis(self):
787+
def basis(self) -> list:
787788
r"""
788789
Return the canonical basis of this Ore module.
789790
@@ -799,14 +800,14 @@ def basis(self):
799800
zero = self.base_ring().zero()
800801
one = self.base_ring().one()
801802
coeffs = [zero] * rank
802-
B = [ ]
803+
B = []
803804
for i in range(rank):
804805
coeffs[i] = one
805806
B.append(self(coeffs))
806807
coeffs[i] = zero
807808
return B
808809

809-
def gens(self):
810+
def gens(self) -> list:
810811
r"""
811812
Return the canonical basis of this Ore module.
812813
@@ -850,7 +851,7 @@ def gen(self, i):
850851
coeffs[i] = one
851852
return self(coeffs)
852853

853-
def an_element(self):
854+
def _an_element_(self):
854855
r"""
855856
Return an element of this Ore module.
856857
@@ -876,8 +877,7 @@ def an_element(self):
876877
"""
877878
if self.rank() > 0:
878879
return self.gen(0)
879-
else:
880-
return self.zero()
880+
return self.zero()
881881

882882
def random_element(self, *args, **kwds):
883883
r"""
@@ -1237,7 +1237,7 @@ def _span(self, gens):
12371237
v = f(v)
12381238
v = v.list()
12391239
for j in range(rank):
1240-
M[i+r,j] = v[j]
1240+
M[i+r, j] = v[j]
12411241
M.echelonize()
12421242
oldr = r
12431243
r = M.rank()
@@ -1406,7 +1406,7 @@ def quotient(self, sub, names=None, check=True):
14061406

14071407
quo = quotient
14081408

1409-
def __eq__(self, other):
1409+
def __eq__(self, other) -> bool:
14101410
r"""
14111411
Return ``True`` if this Ore module is the same than ``other``.
14121412
@@ -1430,7 +1430,7 @@ def __eq__(self, other):
14301430
"""
14311431
return self is other
14321432

1433-
def __hash__(self):
1433+
def __hash__(self) -> int:
14341434
r"""
14351435
Return a hash of this Ore module.
14361436
@@ -1503,7 +1503,7 @@ def __classcall_private__(cls, ambient, gens, names):
15031503
names = normalize_names(names, rank)
15041504
return cls.__classcall__(cls, ambient, basis, names)
15051505

1506-
def __init__(self, ambient, basis, names):
1506+
def __init__(self, ambient, basis, names) -> None:
15071507
r"""
15081508
Initialize this Ore submodule.
15091509
@@ -1541,7 +1541,7 @@ def __init__(self, ambient, basis, names):
15411541
self._inject = coerce.__copy__()
15421542
self.register_conversion(OreModuleRetraction(ambient, self))
15431543

1544-
def _repr_element(self, x):
1544+
def _repr_element(self, x) -> str:
15451545
r"""
15461546
Return a string representation of ``x``.
15471547
@@ -1559,7 +1559,7 @@ def _repr_element(self, x):
15591559
"""
15601560
return self._ambient(x)._repr_()
15611561

1562-
def _latex_element(self, x):
1562+
def _latex_element(self, x) -> str:
15631563
r"""
15641564
Return a LaTeX representation of ``x``.
15651565
@@ -1850,7 +1850,7 @@ def __classcall_private__(cls, cover, gens, names):
18501850
names = normalize_names(names, cover.rank() - rank)
18511851
return cls.__classcall__(cls, cover, basis, names)
18521852

1853-
def __init__(self, cover, basis, names):
1853+
def __init__(self, cover, basis, names) -> None:
18541854
r"""
18551855
Initialize this Ore quotient.
18561856
@@ -1891,10 +1891,10 @@ def __init__(self, cover, basis, names):
18911891
i += 1
18921892
else:
18931893
indices.append(j)
1894-
coerce[j,j-i] = base.one()
1894+
coerce[j, j-i] = base.one()
18951895
for i in range(r):
18961896
for j in range(d-r):
1897-
coerce[pivots[i],j] = -basis[i,indices[j]]
1897+
coerce[pivots[i], j] = -basis[i, indices[j]]
18981898
rows = [cover.gen(i).image() * coerce for i in indices]
18991899
OreModule.__init__(self, matrix(base, rows),
19001900
cover.ore_ring(action=False),
@@ -1904,7 +1904,7 @@ def __init__(self, cover, basis, names):
19041904
self.register_coercion(coerce)
19051905
cover.register_conversion(OreModuleSection(self, cover))
19061906

1907-
def _repr_element(self, x):
1907+
def _repr_element(self, x) -> str:
19081908
r"""
19091909
Return a string representation of `x`.
19101910
@@ -1928,7 +1928,7 @@ def _repr_element(self, x):
19281928
coords[indices[i]] = x[i]
19291929
return M(coords)._repr_()
19301930

1931-
def _latex_element(self, x):
1931+
def _latex_element(self, x) -> str:
19321932
r"""
19331933
Return a LaTeX representation of `x`.
19341934

0 commit comments

Comments
 (0)