Skip to content

Commit 353c544

Browse files
author
Release Manager
committed
gh-40079: typing annotation in Dirichlet characters and also getting rid of an old `set_element_constructor` that was used for old pickles. ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #40079 Reported by: Frédéric Chapoton Reviewer(s): Edgar Costa
2 parents c04cae3 + 622433f commit 353c544

File tree

1 file changed

+28
-37
lines changed

1 file changed

+28
-37
lines changed

src/sage/modular/dirichlet.py

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class DirichletCharacter(MultiplicativeGroupElement):
191191
"""
192192
A Dirichlet character.
193193
"""
194-
def __init__(self, parent, x, check=True):
194+
def __init__(self, parent, x, check=True) -> None:
195195
r"""
196196
Create a Dirichlet character with specified values on
197197
generators of `(\ZZ/n\ZZ)^*`.
@@ -401,7 +401,7 @@ def change_ring(self, R):
401401
G = self.parent().change_ring(R)
402402
return G.element_class(G, [R(x) for x in self.values_on_gens()])
403403

404-
def _richcmp_(self, other, op):
404+
def _richcmp_(self, other, op) -> bool:
405405
"""
406406
Compare ``self`` to ``other``.
407407
@@ -429,7 +429,7 @@ def _richcmp_(self, other, op):
429429
"""
430430
return richcmp(self.values_on_gens(), other.values_on_gens(), op)
431431

432-
def __hash__(self):
432+
def __hash__(self) -> int:
433433
"""
434434
Return the hash of ``self``.
435435
@@ -527,7 +527,7 @@ def __pow__(self, n):
527527
x = tuple(z**n for z in self.values_on_gens())
528528
return G.element_class(G, x, check=False)
529529

530-
def _repr_short_(self):
530+
def _repr_short_(self) -> str:
531531
r"""
532532
A short string representation of ``self``, often used in string representations of modular forms.
533533
@@ -539,7 +539,7 @@ def _repr_short_(self):
539539
"""
540540
return str(list(self.values_on_gens()))
541541

542-
def _repr_(self):
542+
def _repr_(self) -> str:
543543
"""
544544
String representation of ``self``.
545545
@@ -569,7 +569,7 @@ def _repr_(self):
569569
s += str(self.parent().unit_gens()[i]) + ' |--> ' + str(self.values_on_gens()[i])
570570
return s
571571

572-
def _latex_(self):
572+
def _latex_(self) -> str:
573573
r"""
574574
LaTeX representation of ``self``.
575575
@@ -1048,7 +1048,7 @@ def fixed_field(self):
10481048
return NumberField(self.fixed_field_polynomial(), 'a')
10491049

10501050
@cached_method
1051-
def decomposition(self):
1051+
def decomposition(self) -> list:
10521052
r"""
10531053
Return the decomposition of ``self`` as a product of Dirichlet
10541054
characters of prime power modulus, where the prime powers exactly
@@ -1229,7 +1229,7 @@ def conrey_number(self):
12291229
G, v = self._pari_init_()
12301230
return pari.znconreyexp(G, v).sage()
12311231

1232-
def lmfdb_page(self):
1232+
def lmfdb_page(self) -> None:
12331233
r"""
12341234
Open the LMFDB web page of the character in a browser.
12351235
@@ -1246,7 +1246,7 @@ def lmfdb_page(self):
12461246
url = lmfdb_url.format(self.modulus(), self.conrey_number())
12471247
webbrowser.open(url)
12481248

1249-
def galois_orbit(self, sort=True):
1249+
def galois_orbit(self, sort=True) -> list:
12501250
r"""
12511251
Return the orbit of this character under the action of the absolute
12521252
Galois group of the prime subfield of the base ring.
@@ -1548,7 +1548,7 @@ def jacobi_sum(self, char, check=True):
15481548
15491549
And sums where exactly one character is nontrivial (see :issue:`6393`)::
15501550
1551-
sage: G = DirichletGroup(5); X = G.list(); Y=X[0]; Z=X[1]
1551+
sage: G = DirichletGroup(5); X = G.list(); Y = X[0]; Z = X[1]
15521552
sage: Y.jacobi_sum(Z)
15531553
-1
15541554
sage: Z.jacobi_sum(Y)
@@ -1828,7 +1828,7 @@ def is_trivial(self) -> bool:
18281828
one = self.base_ring().one()
18291829
return all(x == one for x in self.values_on_gens())
18301830

1831-
def kernel(self):
1831+
def kernel(self) -> list:
18321832
r"""
18331833
Return the kernel of this character.
18341834
@@ -2042,7 +2042,7 @@ def restrict(self, M):
20422042
return H(self)
20432043

20442044
@cached_method
2045-
def values(self):
2045+
def values(self) -> list:
20462046
"""
20472047
Return a list of the values of this character on each integer
20482048
between 0 and the modulus.
@@ -2130,7 +2130,7 @@ def values(self):
21302130
i += 1
21312131

21322132
@cached_method(do_pickle=True)
2133-
def values_on_gens(self):
2133+
def values_on_gens(self) -> tuple:
21342134
r"""
21352135
Return a tuple of the values of ``self`` on the standard
21362136
generators of `(\ZZ/N\ZZ)^*`, where `N` is the modulus.
@@ -2456,6 +2456,12 @@ class DirichletGroupFactory(UniqueFactory):
24562456
24572457
sage: DirichletGroup(60) is DirichletGroup(60)
24582458
True
2459+
2460+
Test for pickling::
2461+
2462+
sage: G = DirichletGroup(9)
2463+
sage: loads(dumps(G)) is G
2464+
True
24592465
"""
24602466
def create_key(self, N, base_ring=None, zeta=None, zeta_order=None,
24612467
names=None, integral=False):
@@ -2563,7 +2569,7 @@ def create_object(self, version, key, **extra_args):
25632569
DirichletGroup = DirichletGroupFactory("DirichletGroup")
25642570

25652571

2566-
def is_DirichletGroup(x):
2572+
def is_DirichletGroup(x) -> bool:
25672573
"""
25682574
Return ``True`` if ``x`` is a Dirichlet group.
25692575
@@ -2592,7 +2598,7 @@ class DirichletGroup_class(WithEqualityById, Parent):
25922598

25932599
Element = DirichletCharacter
25942600

2595-
def __init__(self, base_ring, modulus, zeta, zeta_order):
2601+
def __init__(self, base_ring, modulus, zeta, zeta_order) -> None:
25962602
"""
25972603
Create a Dirichlet group.
25982604
@@ -2631,21 +2637,6 @@ def __init__(self, base_ring, modulus, zeta, zeta_order):
26312637
self._modulus = modulus
26322638
self._integers = IntegerModRing(modulus)
26332639

2634-
def __setstate__(self, state):
2635-
"""
2636-
Used for unpickling old instances.
2637-
2638-
TESTS::
2639-
2640-
sage: G = DirichletGroup(9)
2641-
sage: loads(dumps(G)) is G
2642-
True
2643-
"""
2644-
self._set_element_constructor()
2645-
if '_zeta_order' in state:
2646-
state['_zeta_order'] = Integer(state['_zeta_order'])
2647-
super().__setstate__(state)
2648-
26492640
@property
26502641
def _module(self):
26512642
"""
@@ -2686,7 +2677,7 @@ def _zeta_powers(self):
26862677
return w
26872678

26882679
@property
2689-
def _zeta_dlog(self):
2680+
def _zeta_dlog(self) -> dict:
26902681
"""
26912682
Return a dictionary that can be used to compute discrete
26922683
logarithms in the value group of this Dirichlet group.
@@ -2870,7 +2861,7 @@ def _element_constructor_(self, x):
28702861
a.append(R(x(v)))
28712862
return self.element_class(self, a)
28722863

2873-
def _coerce_map_from_(self, X):
2864+
def _coerce_map_from_(self, X) -> bool:
28742865
"""
28752866
Decide whether there is a coercion map from `X`.
28762867
@@ -2915,7 +2906,7 @@ def __len__(self):
29152906
"""
29162907
return self.order()
29172908

2918-
def _repr_(self):
2909+
def _repr_(self) -> str:
29192910
"""
29202911
Return a print representation of this group, which can be renamed.
29212912
@@ -2935,7 +2926,7 @@ def _repr_(self):
29352926
return s
29362927

29372928
@cached_method
2938-
def decomposition(self):
2929+
def decomposition(self) -> list:
29392930
r"""
29402931
Return the Dirichlet groups of prime power modulus corresponding
29412932
to primes dividing modulus.
@@ -3140,7 +3131,7 @@ def integers_mod(self):
31403131

31413132
__iter__ = multiplicative_iterator
31423133

3143-
def list(self):
3134+
def list(self) -> list:
31443135
"""
31453136
Return a list of the Dirichlet characters in this group.
31463137
@@ -3166,7 +3157,7 @@ def modulus(self):
31663157
"""
31673158
return self._modulus
31683159

3169-
def ngens(self):
3160+
def ngens(self) -> int:
31703161
"""
31713162
Return the number of generators of ``self``.
31723163
@@ -3244,7 +3235,7 @@ def random_element(self):
32443235
e *= g**n
32453236
return e
32463237

3247-
def unit_gens(self):
3238+
def unit_gens(self) -> tuple:
32483239
r"""
32493240
Return the minimal generators for the units of
32503241
`(\ZZ/N\ZZ)^*`, where `N` is the

0 commit comments

Comments
 (0)