Skip to content

Commit ef30112

Browse files
committed
add some typing in modular,modules,plot,schemes,symbolic,topology
1 parent aa27703 commit ef30112

File tree

13 files changed

+89
-87
lines changed

13 files changed

+89
-87
lines changed

src/sage/modular/abvar/finite_subgroup.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class FiniteSubgroup(Module):
143143

144144
Element = TorsionPoint
145145

146-
def __init__(self, abvar, field_of_definition=QQ):
146+
def __init__(self, abvar, field_of_definition=QQ) -> None:
147147
"""
148148
Initialize ``self``.
149149
@@ -215,7 +215,7 @@ def _relative_basis_matrix(self):
215215
return M
216216

217217
# General functionality
218-
def __richcmp__(self, other, op):
218+
def __richcmp__(self, other, op) -> bool:
219219
"""
220220
Compare ``self`` to ``other``.
221221
@@ -693,7 +693,7 @@ def _element_constructor_(self, x, check=True):
693693
x = self.lattice()(x, check=check)
694694
return self.element_class(self, x, check=False)
695695

696-
def __contains__(self, x):
696+
def __contains__(self, x) -> bool:
697697
"""
698698
Return ``True`` if ``x`` is contained in this finite subgroup.
699699
@@ -837,7 +837,8 @@ def invariants(self):
837837

838838

839839
class FiniteSubgroup_lattice(FiniteSubgroup):
840-
def __init__(self, abvar, lattice, field_of_definition=None, check=True):
840+
def __init__(self, abvar, lattice,
841+
field_of_definition=None, check=True) -> None:
841842
"""
842843
A finite subgroup of a modular abelian variety that is defined by a
843844
given lattice.

src/sage/modular/arithgroup/arithgroup_generic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def _element_constructor_(self, x, check=True):
145145
return x
146146
raise TypeError("matrix %s is not an element of %s" % (x, self))
147147

148-
def __contains__(self, x):
148+
def __contains__(self, x) -> bool:
149149
r"""
150150
Test if x is an element of this group.
151151
@@ -200,7 +200,7 @@ def _contains_sl2(self, a, b, c, d):
200200
"""
201201
raise NotImplementedError("Please implement _contains_sl2 for %s" % self.__class__)
202202

203-
def __hash__(self):
203+
def __hash__(self) -> int:
204204
r"""
205205
Return a hash of ``self``.
206206

src/sage/modular/arithgroup/farey_symbol.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ cdef class Farey:
511511
else: # output == 'gens'
512512
return tuple((gens[a-1], len(list(g))) if a > 0 else (gens[-a-1], -len(list(g))) for a, g in groupby(tietze))
513513

514-
def __contains__(self, M):
514+
def __contains__(self, M) -> bool:
515515
r"""
516516
Test if element is in the arithmetic group of the Farey symbol
517517
via LLT algorithm.
@@ -533,7 +533,7 @@ cdef class Farey:
533533
sig_off()
534534
return result
535535

536-
def __richcmp__(self, other, op):
536+
def __richcmp__(self, other, op) -> bool:
537537
r"""
538538
Compare ``self`` to ``other``.
539539

@@ -569,7 +569,7 @@ cdef class Farey:
569569
"""
570570
return Farey, (self.group, self.this_ptr.dumps())
571571

572-
def __repr__(self):
572+
def __repr__(self) -> str:
573573
r"""
574574
Return the string representation of ``self``.
575575

src/sage/modules/fg_pid/fgp_module.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ class FGP_Module_class(Module):
336336
# module. Should be overridden in derived classes.
337337
Element = FGP_Element
338338

339-
def __init__(self, V, W, check=True):
339+
def __init__(self, V, W, check=True) -> None:
340340
"""
341341
INPUT:
342342
@@ -470,7 +470,7 @@ def _mul_(self, other, switch_sides=False):
470470
raise ValueError("Scalar multiplication of a module is only " +
471471
"defined for an element of the base ring.")
472472

473-
def _repr_(self):
473+
def _repr_(self) -> str:
474474
"""
475475
Return string representation of this module.
476476
@@ -507,9 +507,9 @@ def __truediv__(self, other):
507507
raise TypeError("other must be an FGP module")
508508
if not other.is_submodule(self):
509509
raise ValueError("other must be a submodule of self")
510-
return self._module_constructor(self._V, other._V+self._W)
510+
return self._module_constructor(self._V, other._V + self._W)
511511

512-
def __eq__(self, other):
512+
def __eq__(self, other) -> bool:
513513
"""
514514
EXAMPLES::
515515
@@ -529,7 +529,7 @@ def __eq__(self, other):
529529
return False
530530
return self._V == other._V and self._W == other._W
531531

532-
def __ne__(self, other):
532+
def __ne__(self, other) -> bool:
533533
"""
534534
Return ``True`` iff ``self`` is not equal to ``other``.
535535
@@ -569,7 +569,7 @@ def __ne__(self, other):
569569

570570
# __le__ is a synonym for `is_submodule`: see below
571571

572-
def __lt__(self, other):
572+
def __lt__(self, other) -> bool:
573573
"""
574574
Return ``True`` iff ``self`` is a proper submodule of ``other``.
575575
@@ -587,7 +587,7 @@ def __lt__(self, other):
587587
"""
588588
return self <= other and not self == other
589589

590-
def __gt__(self, other):
590+
def __gt__(self, other) -> bool:
591591
"""
592592
Return ``True`` iff ``other`` is a proper submodule of ``self``.
593593
@@ -605,7 +605,7 @@ def __gt__(self, other):
605605
"""
606606
return self >= other and not self == other
607607

608-
def __ge__(self, other):
608+
def __ge__(self, other) -> bool:
609609
"""
610610
Return ``True`` iff ``other`` is a submodule of ``self``.
611611
@@ -675,7 +675,7 @@ def linear_combination_of_smith_form_gens(self, x):
675675
raise TypeError(msg)
676676
return self.element_class(self, self._V(x))
677677

678-
def __contains__(self, x):
678+
def __contains__(self, x) -> bool:
679679
"""
680680
Return true if ``x`` is contained in ``self``.
681681
@@ -1940,7 +1940,7 @@ def ngens(self):
19401940
"""
19411941
return len(self.gens())
19421942

1943-
def __hash__(self):
1943+
def __hash__(self) -> int:
19441944
r"""
19451945
Calculate a hash for ``self``.
19461946

src/sage/modules/with_basis/indexed_element.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ cdef class IndexedFreeModuleElement(ModuleElement):
4747
sage: isinstance(f, collections.abc.Collection) # known bug - will be fixed by removing __contains__
4848
False
4949
"""
50-
def __init__(self, M, x):
50+
def __init__(self, M, x) -> None:
5151
"""
5252
Create a combinatorial module element.
5353

@@ -84,7 +84,7 @@ cdef class IndexedFreeModuleElement(ModuleElement):
8484
"""
8585
return iter(self._monomial_coefficients.items())
8686

87-
def __contains__(self, x):
87+
def __contains__(self, x) -> bool:
8888
"""
8989
Return whether or not a combinatorial object ``x`` indexing a basis
9090
element is in the support of ``self``.
@@ -113,7 +113,7 @@ cdef class IndexedFreeModuleElement(ModuleElement):
113113
deprecation(34509, "using 'index in vector' is deprecated; use 'index in vector.support()' instead")
114114
return x in self.support()
115115

116-
def __hash__(self):
116+
def __hash__(self) -> int:
117117
"""
118118
Return the hash value for ``self``.
119119

src/sage/plot/colors.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def rgbcolor(c, space='rgb'):
353353

354354

355355
class Color:
356-
def __init__(self, r='#0000ff', g=None, b=None, space='rgb'):
356+
def __init__(self, r='#0000ff', g=None, b=None, space='rgb') -> None:
357357
"""
358358
A Red-Green-Blue (RGB) color model color object. For most
359359
consumer-grade devices (e.g., CRTs, LCDs, and printers), as
@@ -400,7 +400,7 @@ def __init__(self, r='#0000ff', g=None, b=None, space='rgb'):
400400
else:
401401
self._rgb = rgbcolor((r, g, b), space=space)
402402

403-
def __repr__(self):
403+
def __repr__(self) -> str:
404404
"""
405405
Return a string representation of this color.
406406
@@ -415,7 +415,7 @@ def __repr__(self):
415415
"""
416416
return f"RGB color {self._rgb}"
417417

418-
def __lt__(self, right):
418+
def __lt__(self, right) -> bool:
419419
"""
420420
Check whether a :class:`Color` object is less than some other
421421
object. This doesn't make sense, and so we conclude that it is
@@ -438,7 +438,7 @@ def __lt__(self, right):
438438
"""
439439
return False
440440

441-
def __le__(self, right):
441+
def __le__(self, right) -> bool:
442442
"""
443443
Check whether a :class:`Color` object is less than or equal to
444444
some other object. It wouldn't make sense for it to be less than
@@ -462,7 +462,7 @@ def __le__(self, right):
462462
"""
463463
return self == right
464464

465-
def __eq__(self, right):
465+
def __eq__(self, right) -> bool:
466466
"""
467467
Compare two :class:`Color` objects to determine whether
468468
they refer to the same color.
@@ -489,7 +489,7 @@ def __eq__(self, right):
489489
return self._rgb == right._rgb
490490
return False
491491

492-
def __ne__(self, right):
492+
def __ne__(self, right) -> bool:
493493
"""
494494
Compare two :class:`Color` objects to determine whether
495495
they refer to different colors.
@@ -516,7 +516,7 @@ def __ne__(self, right):
516516
"""
517517
return not (self == right)
518518

519-
def __gt__(self, right):
519+
def __gt__(self, right) -> bool:
520520
"""
521521
Check whether a :class:`Color` object is greater than some other
522522
object. This doesn't make sense, and so we conclude that it is
@@ -539,7 +539,7 @@ def __gt__(self, right):
539539
"""
540540
return False
541541

542-
def __ge__(self, right):
542+
def __ge__(self, right) -> bool:
543543
"""
544544
Check whether a :class:`Color` object is greater than or equal
545545
to some other object. It wouldn't make sense for it to be
@@ -563,7 +563,7 @@ def __ge__(self, right):
563563
"""
564564
return self == right
565565

566-
def __hash__(self):
566+
def __hash__(self) -> int:
567567
"""
568568
Return the hash value of a color.
569569
Equal colors return equal hash values.
@@ -1004,7 +1004,7 @@ class ColorsDict(dict):
10041004
sage: sorted(colors)
10051005
['aliceblue', 'antiquewhite', 'aqua', 'aquamarine', ...]
10061006
"""
1007-
def __init__(self):
1007+
def __init__(self) -> None:
10081008
"""
10091009
Construct a dict-like collection of colors. The keys are the
10101010
color names (i.e., strings) and the values are RGB 3-tuples of
@@ -1364,7 +1364,7 @@ class Colormaps(MutableMapping):
13641364
sage: sorted(colormaps)
13651365
['Accent', ...]
13661366
"""
1367-
def __init__(self):
1367+
def __init__(self) -> None:
13681368
"""
13691369
Construct an empty mutable collection of color maps.
13701370
@@ -1418,7 +1418,7 @@ def __dir__(self):
14181418
'__setitem__', '__delitem__']
14191419
return dir(super()) + methods + sorted(self)
14201420

1421-
def __len__(self):
1421+
def __len__(self) -> int:
14221422
"""
14231423
Return the number of color maps.
14241424
@@ -1452,7 +1452,7 @@ def __iter__(self):
14521452
self.load_maps()
14531453
return iter(self.maps)
14541454

1455-
def __contains__(self, name):
1455+
def __contains__(self, name) -> bool:
14561456
"""
14571457
Return whether a map is in the color maps collection.
14581458
@@ -1536,7 +1536,7 @@ def __getattr__(self, name):
15361536
except KeyError:
15371537
raise AttributeError("'{}' has no attribute or colormap {}".format(type(self).__name__, name))
15381538

1539-
def __repr__(self):
1539+
def __repr__(self) -> str:
15401540
"""
15411541
Return a string representation of the color map collection.
15421542

src/sage/schemes/elliptic_curves/ell_generic.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class EllipticCurve_generic(WithEqualityById, plane_curve.ProjectivePlaneCurve):
124124
sage: -5*P
125125
(179051/80089 : -91814227/22665187 : 1)
126126
"""
127-
def __init__(self, K, ainvs, category=None):
127+
def __init__(self, K, ainvs, category=None) -> None:
128128
r"""
129129
Construct an elliptic curve from Weierstrass `a`-coefficients.
130130
@@ -465,7 +465,7 @@ def _symbolic_(self, SR):
465465
x, y = SR.var('x, y')
466466
return y**2 + a[0]*x*y + a[2]*y == x**3 + a[1]*x**2 + a[3]*x + a[4]
467467

468-
def __contains__(self, P):
468+
def __contains__(self, P) -> bool:
469469
"""
470470
Return ``True`` if and only if P is a point on the elliptic curve.
471471
@@ -1049,7 +1049,7 @@ def __getitem__(self, n):
10491049
"""
10501050
raise NotImplementedError("not implemented.")
10511051

1052-
def __is_over_RationalField(self):
1052+
def __is_over_RationalField(self) -> bool:
10531053
r"""
10541054
Internal function. Return true iff the base ring of this elliptic
10551055
curve is the field of rational numbers.
@@ -1065,7 +1065,7 @@ def __is_over_RationalField(self):
10651065
"""
10661066
return isinstance(self.base_ring(), RationalField)
10671067

1068-
def is_on_curve(self, x, y):
1068+
def is_on_curve(self, x, y) -> bool:
10691069
r"""
10701070
Return ``True`` if `(x,y)` is an affine point on this curve.
10711071

0 commit comments

Comments
 (0)