8000 typing annotation in Dirichlet characters by fchapoton · Pull Request #40079 · sagemath/sage · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

typing annotation in Dirichlet characters #40079

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

Merged
merged 1 commit into from
May 18, 2025
Merged
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
65 changes: 28 additions & 37 deletions src/sage/modular/dirichlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class DirichletCharacter(MultiplicativeGroupElement):
"""
A Dirichlet character.
"""
def __init__(self, parent, x, check=True):
def __init__(self, parent, x, check=True) -> None:
r"""
Create a Dirichlet character with specified values on
generators of `(\ZZ/n\ZZ)^*`.
Expand Down Expand Up @@ -401,7 +401,7 @@ def change_ring(self, R):
G = self.parent().change_ring(R)
return G.element_class(G, [R(x) for x in self.values_on_gens()])

def _richcmp_(self, other, op):
def _richcmp_(self, other, op) -> bool:
"""
Compare ``self`` to ``other``.

Expand Down Expand Up @@ -429,7 +429,7 @@ def _richcmp_(self, other, op):
"""
return richcmp(self.values_on_gens(), other.values_on_gens(), op)

def __hash__(self):
def __hash__(self) -> int:
"""
Return the hash of ``self``.

Expand Down Expand Up @@ -527,7 +527,7 @@ def __pow__(self, n):
x = tuple(z**n for z in self.values_on_gens())
return G.element_class(G, x, check=False)

def _repr_short_(self):
def _repr_short_(self) -> str:
r"""
A short string representation of ``self``, often used in string representations of modular forms.

Expand All @@ -539,7 +539,7 @@ def _repr_short_(self):
"""
return str(list(self.values_on_gens()))

def _repr_(self):
def _repr_(self) -> str:
"""
String representation of ``self``.

Expand Down Expand Up @@ -569,7 +569,7 @@ def _repr_(self):
s += str(self.parent().unit_gens()[i]) + ' |--> ' + str(self.values_on_gens()[i])
return s

def _latex_(self):
def _latex_(self) -> str:
r"""
LaTeX representation of ``self``.

Expand Down Expand Up @@ -1048,7 +1048,7 @@ def fixed_field(self):
return NumberField(self.fixed_field_polynomial(), 'a')

@cached_method
def decomposition(self):
def decomposition(self) -> list:
r"""
Return the decomposition of ``self`` as a product of Dirichlet
characters of prime power modulus, where the prime powers exactly
Expand Down Expand Up @@ -1229,7 +1229,7 @@ def conrey_number(self):
G, v = self._pari_init_()
return pari.znconreyexp(G, v).sage()

def lmfdb_page(self):
def lmfdb_page(self) -> None:
r"""
Open the LMFDB web page of the character in a browser.

Expand All @@ -1246,7 +1246,7 @@ def lmfdb_page(self):
url = lmfdb_url.format(self.modulus(), self.conrey_number())
webbrowser.open(url)

def galois_orbit(self, sort=True):
def galois_orbit(self, sort=True) -> list:
r"""
Return the orbit of this character under the action of the absolute
Galois group of the prime subfield of the base ring.
Expand Down Expand Up @@ -1548,7 +1548,7 @@ def jacobi_sum(self, char, check=True):

And sums where exactly one character is nontrivial (see :issue:`6393`)::

sage: G = DirichletGroup(5); X = G.list(); Y=X[0]; Z=X[1]
sage: G = DirichletGroup(5); X = G.list(); Y = X[0]; Z = X[1]
sage: Y.jacobi_sum(Z)
-1
sage: Z.jacobi_sum(Y)
Expand Down Expand Up @@ -1828,7 +1828,7 @@ def is_trivial(self) -> bool:
>
return all(x == one for x in self.values_on_gens())

def kernel(self):
def kernel(self) -> list:
r"""
Return the kernel of this character.

Expand Down Expand Up @@ -2042,7 +2042,7 @@ def restrict(self, M):
return H(self)

@cached_method
def values(self):
def values(self) -> list:
"""
Return a list of the values of this character on each integer
between 0 and the modulus.
Expand Down Expand Up @@ -2130,7 +2130,7 @@ def values(self):
i += 1

@cached_method(do_pickle=True)
def values_on_gens(self):
def values_on_gens(self) -> tuple:
r"""
Return a tuple of the values of ``self`` on the standard
generators of `(\ZZ/N\ZZ)^*`, where `N` is the modulus.
Expand Down Expand Up @@ -2456,6 +2456,12 @@ class DirichletGroupFactory(UniqueFactory):

sage: DirichletGroup(60) is DirichletGroup(60)
True

Test for pickling::

sage: G = DirichletGroup(9)
sage: loads(dumps(G)) is G
True
"""
def create_key(self, N, base_ring=None, zeta=None, zeta_order=None,
names=None, integral=False):
Expand Down Expand Up @@ -2563,7 +2569,7 @@ def create_object(self, version, key, **extra_args):
DirichletGroup = DirichletGroupFactory("DirichletGroup")


def is_DirichletGroup(x):
def is_DirichletGroup(x) -> bool:
"""
Return ``True`` if ``x`` is a Dirichlet group.

Expand Down Expand Up @@ -2592,7 +2598,7 @@ class DirichletGroup_class(WithEqualityById, Parent):

Element = DirichletCharacter

def __init__(self, base_ring, modulus, zeta, zeta_order):
def __init__(self, base_ring, modulus, zeta, zeta_order) -> None:
"""
Create a Dirichlet group.

Expand Down Expand Up @@ -2631,21 +2637,6 @@ def __init__(self, base_ring, modulus, zeta, zeta_order):
self._modulus = modulus
self._integers = IntegerModRing(modulus)

def __setstate__(self, state):
"""
Used for unpickling old instances.

TESTS::

sage: G = DirichletGroup(9)
sage: loads(dumps(G)) is G
True
"""
self._set_element_constructor()
if '_zeta_order' in state:
state['_zeta_order'] = Integer(state['_zeta_order'])
super().__setstate__(state)

@property
def _module(self):
"""
Expand Down Expand Up @@ -2686,7 +2677,7 @@ def _zeta_powers(self):
return w

@property
def _zeta_dlog(self):
def _zeta_dlog(self) -> dict:
"""
Return a dictionary that can be used to compute discrete
logarithms in the value group of this Dirichlet group.
Expand Down Expand Up @@ -2870,7 +2861,7 @@ def _element_constructor_(self, x):
a.append(R(x(v)))
return self.element_class(self, a)

def _coerce_map_from_(self, X):
def _coerce_map_from_(self, X) -> bool:
"""
Decide whether there is a coercion map from `X`.

Expand Down Expand Up @@ -2915,7 +2906,7 @@ def __len__(self):
"""
return self.order()

def _repr_(self):
def _repr_(self) -> str:
"""
Return a print representation of this group, which can be renamed.

Expand All @@ -2935,7 +2926,7 @@ def _repr_(self):
return s

@cached_method
def decomposition(self):
def decomposition(self) -> list:
r"""
Return the Dirichlet groups of prime power modulus corresponding
to primes dividing modulus.
Expand Down Expand Up @@ -3140,7 +3131,7 @@ def integers_mod(self):

__iter__ = multiplicative_iterator

def list(self):
def list(self) -> list:
"""
Return a list of the Dirichlet characters in this group.

Expand All @@ -3166,7 +3157,7 @@ def modulus(self):
"""
return self._modulus

def ngens(self):
def ngens(self) -> int:
"""
Return the number of generators of ``self``.

Expand Down Expand Up @@ -3244,7 +3235,7 @@ def random_element(self):
e *= g**n
return e

def unit_gens(self):
def unit_gens(self) -> tuple:
r"""
Return the minimal generators for the units of
`(\ZZ/N\ZZ)^*`, where `N` is the
Expand Down
Loading
0