Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some typing annotations to gens methods (-> tuple) #39233

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/sage/rings/algebraic_closure_finite_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@

- Vincent Delecroix (November 2013): additional methods
"""

from sage.misc.abstract_method import abstract_method
from sage.misc.fast_methods import WithEqualityById

from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.rings.ring import Field
from sage.sets.family import AbstractFamily
from sage.structure.element import Element, FieldElement
from sage.structure.richcmp import richcmp

Expand Down Expand Up @@ -833,7 +832,7 @@ def gen(self, n):
F = self._subfield(n)
return self(F.gen())

def gens(self):
def gens(self) -> AbstractFamily:
"""
Return a family of generators of ``self``.

Expand Down
14 changes: 7 additions & 7 deletions src/sage/rings/asymptotic/growth_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2370,7 +2370,7 @@ def _pushout_(self, other):
from sage.categories.cartesian_product import cartesian_product
return cartesian_product([self, other])

def gens_monomial(self):
def gens_monomial(self) -> tuple:
r"""
Return a tuple containing monomial generators of this growth
group.
Expand Down Expand Up @@ -2399,9 +2399,9 @@ def gens_monomial(self):
sage: GrowthGroup('QQ^x').gens_monomial()
()
"""
return tuple()
return ()

def gens(self):
def gens(self) -> tuple:
r"""
Return a tuple of all generators of this growth group.

Expand Down Expand Up @@ -3519,7 +3519,7 @@ def _split_raw_element_(raw_element):
from sage.functions.other import real, imag
return real(raw_element), imag(raw_element)

def gens_monomial(self):
def gens_monomial(self) -> tuple:
r"""
Return a tuple containing monomial generators of this growth
group.
Expand All @@ -3546,7 +3546,7 @@ def gens_monomial(self):
return tuple()
return (self(raw_element=self.base().one()),)

def gens_logarithmic(self):
def gens_logarithmic(self) -> tuple:
r"""
Return a tuple containing logarithmic generators of this growth
group.
Expand Down Expand Up @@ -4529,7 +4529,7 @@ def some_elements(self):
return iter(self.element_class(self, e)
for e in self.base().some_elements() if e > 0)

def gens(self):
def gens(self) -> tuple:
r"""
Return a tuple of all generators of this exponential growth
group.
Expand All @@ -4543,7 +4543,7 @@ def gens(self):
sage: E.gens()
()
"""
return tuple()
return ()

def construction(self):
r"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/asymptotic/growth_group_cartesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ def next_custom(self):
from sage.categories.cartesian_product import cartesian_product
return pushout(cartesian_product(newS), cartesian_product(newO))

def gens_monomial(self):
def gens_monomial(self) -> tuple:
r"""
Return a tuple containing monomial generators of this growth group.

Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/derivation.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ def ngens(self):
raise NotImplementedError("generators are not implemented for this derivation module")
return len(self._gens)

def gens(self):
def gens(self) -> tuple:
r"""
Return the generators of this module of derivations.

Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/function_field/ideal.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ def module(self):
"""
return self._module

def gens(self):
def gens(self) -> tuple:
"""
Return a set of generators of this ideal.

Expand Down
19 changes: 9 additions & 10 deletions src/sage/rings/function_field/ideal_polymod.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def module(self):
return V.span([to(g) for g in self.gens_over_base()], base_ring=O)

@cached_method
def gens_over_base(self):
def gens_over_base(self) -> tuple:
"""
Return the generators of this ideal as a module over the maximal order
of the base rational function field.
Expand Down Expand Up @@ -624,7 +624,7 @@ def _gens_over_base(self):
for row in self._hnf]
return gens, self._denominator

def gens(self):
def gens(self) -> tuple:
"""
Return a set of generators of this ideal.

Expand Down Expand Up @@ -1108,7 +1108,7 @@ def __pow__(self, mod):

return generic_power(self, mod)

def gens(self):
def gens(self) -> tuple:
"""
Return a set of generators of this ideal.

Expand All @@ -1134,10 +1134,9 @@ def gens(self):
"""
if self._gens_two.is_in_cache():
return self._gens_two.cache
else:
return self.gens_over_base()
return self.gens_over_base()

def gens_two(self):
def gens_two(self) -> tuple:
r"""
Return two generators of this fractional ideal.

Expand Down Expand Up @@ -1173,7 +1172,7 @@ def gens_two(self):
return tuple(e / d for e in self._gens_two())

@cached_method
def _gens_two(self):
def _gens_two(self) -> tuple:
r"""
Return a set of two generators of the integral ideal, that is
the denominator times this fractional ideal.
Expand Down Expand Up @@ -1556,7 +1555,7 @@ def _relative_degree(self):

return self._ideal._relative_degree

def gens(self):
def gens(self) -> tuple:
"""
Return a set of generators of this ideal.

Expand All @@ -1582,7 +1581,7 @@ def gens(self):
iF, from_iF, to_iF = F._inversion_isomorphism()
return tuple(from_iF(b) for b in self._ideal.gens())

def gens_two(self):
def gens_two(self) -> tuple:
"""
Return a set of at most two generators of this ideal.

Expand All @@ -1608,7 +1607,7 @@ def gens_two(self):
iF, from_iF, to_iF = F._inversion_isomorphism()
return tuple(from_iF(b) for b in self._ideal.gens_two())

def gens_over_base(self):
def gens_over_base(self) -> tuple:
"""
Return a set of generators of this ideal.

Expand Down
8 changes: 4 additions & 4 deletions src/sage/rings/function_field/ideal_rational.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def gen(self):
"""
return self._gen

def gens(self):
def gens(self) -> tuple:
"""
Return the tuple of the unique generator of this ideal.

Expand All @@ -267,7 +267,7 @@ def gens(self):
"""
return (self._gen,)

def gens_over_base(self):
def gens_over_base(self) -> tuple:
"""
Return the generator of this ideal as a rank one module over the maximal
order.
Expand Down Expand Up @@ -548,7 +548,7 @@ def gen(self):
"""
return self._gen

def gens(self):
def gens(self) -> tuple:
"""
Return the generator of this principal ideal.

Expand All @@ -563,7 +563,7 @@ def gens(self):
"""
return (self._gen,)

def gens_over_base(self):
def gens_over_base(self) -> tuple:
"""
Return the generator of this ideal as a rank one module
over the infinite maximal order.
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/ideal.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def __init__(self, ring, gens, coerce=True, **kwds):
gens = [ring(x) for x in gens]

gens = tuple(gens)
if len(gens) == 0:
if not gens:
gens = (ring.zero(),)
self.__gens = gens
MonoidElement.__init__(self, ring.ideal_monoid())
Expand Down Expand Up @@ -622,7 +622,7 @@ def reduce(self, f):
"""
return f # default

def gens(self):
def gens(self): # -> tuple | PolynomialSequence
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also not a class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and I did not make any serious analysis of the possible types that can appear here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use from sage.structure.sequence import Sequence_generic maybe. But I would rather keep it as it is now.

"""
Return a set of generators / a basis of ``self``.

Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/lazy_series_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ def ngens(self):
return 1

@cached_method
def gens(self):
def gens(self) -> tuple:
"""
Return the generators of ``self``.

Expand Down Expand Up @@ -2168,7 +2168,7 @@ def ngens(self):
return len(self.variable_names())

@cached_method
def gens(self):
def gens(self) -> tuple:
"""
Return the generators of ``self``.

Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ def gen(self, i):
"""
return self(self.base_ring().gen(i))

def gens(self):
def gens(self) -> tuple:
"""
Return a tuple whose entries are the generators for this
object, in order.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/number_field/class_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def representative_prime(self, norm_bound=1000):
return P
raise RuntimeError("No prime of norm less than %s found in class %s" % (norm_bound, c))

def gens(self):
def gens(self) -> tuple:
r"""
Return generators for a representative ideal in this
(`S`-)ideal class.
Expand Down
6 changes: 3 additions & 3 deletions src/sage/rings/number_field/number_field_ideal.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ def gens_reduced(self, proof=None):
self._cache_bnfisprincipal(proof=proof, gens=True)
return self._reduced_generators

def gens_two(self):
def gens_two(self) -> tuple:
r"""
Express this ideal using exactly two generators, the first of
which is a generator for the intersection of the ideal with `\QQ`.
Expand Down Expand Up @@ -861,8 +861,8 @@ def gens_two(self):
HNF = self.pari_hnf()
# Check whether the ideal is generated by an integer, i.e.
# whether HNF is a multiple of the identity matrix
if HNF.gequal(HNF[0,0]):
a = HNF[0,0]
if HNF.gequal(HNF[0, 0]):
a = HNF[0, 0]
alpha = 0
else:
a, alpha = K.pari_nf().idealtwoelt(HNF)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/number_field/number_field_rel.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def is_absolute(self):
"""
return False

def gens(self):
def gens(self) -> tuple:
"""
Return the generators of this relative number field.

Expand Down
6 changes: 3 additions & 3 deletions src/sage/rings/number_field/order_ideal.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def conjugate(self):
conj_gens = [g.conjugate() for g in self.gens()]
return NumberFieldOrderIdeal(self.ring(), conj_gens)

def gens_two(self):
def gens_two(self) -> tuple:
r"""
Express this ideal using exactly two generators, the first of
which is a generator for the intersection of the ideal with `\ZZ`.
Expand Down Expand Up @@ -506,7 +506,7 @@ def is_principal(self):
sol = f.solve_integer(-1)
return sol is not None

def gens_reduced(self):
def gens_reduced(self) -> tuple:
r"""
Express this ideal in terms of at most two generators,
and one if possible (i.e., if the ideal is principal).
Expand Down Expand Up @@ -550,7 +550,7 @@ def gens_reduced(self):
sol = f.solve_integer(-1)
if sol is None:
return self.gens_two()
gen = sum(c*g for c,g in zip(sol, bas))
gen = sum(c * g for c, g in zip(sol, bas))
assert NumberFieldOrderIdeal(self.ring(), gen) == self
return (gen,)

Expand Down
20 changes: 6 additions & 14 deletions src/sage/rings/padics/padic_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,20 @@ def ngens(self):
"""
return 1

def gens(self):
def gens(self) -> tuple:
r"""
Return a list of generators.
Return a tuple of generators.

EXAMPLES::

sage: R = Zp(5); R.gens()
[5 + O(5^21)]
(5 + O(5^21),)
sage: Zq(25,names='a').gens() # needs sage.libs.ntl
[a + O(5^20)]
(a + O(5^20),)
sage: S.<x> = ZZ[]; f = x^5 + 25*x -5; W.<w> = R.ext(f); W.gens() # needs sage.libs.ntl
[w + O(w^101)]
(w + O(w^101),)
"""
return [self.gen()]
return (self.gen(),)

def __richcmp__(self, other, op):
r"""
Expand Down Expand Up @@ -195,14 +195,6 @@ def __richcmp__(self, other, op):

return self._printer.richcmp_modes(other._printer, op)

# def ngens(self):
# return 1

# def gen(self, n=0):
# if n != 0:
# raise IndexError, "only one generator"
# return self(self.prime())

def print_mode(self):
r"""
Return the current print mode as a string.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/polynomial/infinite_polynomial_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ def _first_ngens(self, n):
return self.gens()[-n:]

@cached_method
def gens_dict(self):
def gens_dict(self) -> GenDictWithBasering:
"""
Return a dictionary-like object containing the infinitely many
``{var_name:variable}`` pairs.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/polynomial/laurent_polynomial_ideal.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def __contains__(self, f):
g = f.__reduce__()[1][0]
return (g in self.polynomial_ideal())

def gens_reduced(self):
def gens_reduced(self) -> tuple:
"""
Return a reduced system of generators.

Expand Down
Loading
Loading