Skip to content

Commit 7ced31e

Browse files
author
Release Manager
committed
gh-40262: Minor modernization by removing outdated workarounds <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes #12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes #12345". --> Removing some old code that is only required for Python <= 3.10. Minor stylistic cleanup of the touched files (mostly reordering of the imports). ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [ ] The title is concise and informative. - [ ] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #40262 Reported by: Tobias Diez Reviewer(s): Frédéric Chapoton, Tobias Diez, user202729
2 parents 0528c99 + d689a07 commit 7ced31e

File tree

4 files changed

+177
-160
lines changed

4 files changed

+177
-160
lines changed

src/sage/misc/cython.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@
2222
import builtins
2323
import os
2424
import re
25-
import sys
2625
import shutil
26+
import sys
2727
import webbrowser
2828
from pathlib import Path
2929

30-
from sage.env import (SAGE_LOCAL, cython_aliases,
31-
sage_include_directories)
30+
from sage.env import SAGE_LOCAL, cython_aliases, sage_include_directories
3231
from sage.misc.cachefunc import cached_function
33-
from sage.misc.sage_ostools import restore_cwd, redirection
32+
from sage.misc.sage_ostools import redirection, restore_cwd
3433
from sage.misc.temporary_file import spyx_tmp, tmp_filename
3534
from sage.repl.user_globals import get_globals
3635

@@ -355,20 +354,13 @@ def cython(filename, verbose=0, compile_message=False,
355354
includes = [os.getcwd()] + standard_includes
356355

357356
# Now do the actual build, directly calling Cython and distutils
357+
from distutils.log import set_verbosity
358+
359+
import Cython.Compiler.Options
358360
from Cython.Build import cythonize
359361
from Cython.Compiler.Errors import CompileError
360-
import Cython.Compiler.Options
361-
362-
try:
363-
from setuptools.dist import Distribution
364-
from setuptools.extension import Extension
365-
except ImportError:
366-
# Fall back to distutils (stdlib); note that it is deprecated
367-
# in Python 3.10, 3.11; https://www.python.org/dev/peps/pep-0632/
368-
from distutils.dist import Distribution
369-
from distutils.core import Extension
370-
371-
from distutils.log import set_verbosity
362+
from setuptools.dist import Distribution
363+
from setuptools.extension import Extension
372364
set_verbosity(verbose)
373365

374366
Cython.Compiler.Options.annotate = annotate

src/sage/quadratic_forms/genera/genus.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,22 @@
1818
#
1919
# https://www.gnu.org/licenses/
2020
# ****************************************************************************
21-
from pathlib import Path
2221
from copy import copy, deepcopy
22+
from pathlib import Path
2323

24-
from sage.misc.lazy_import import lazy_import
25-
from sage.misc.misc_c import prod
26-
from sage.misc.cachefunc import cached_method
2724
from sage.arith.functions import lcm as LCM
2825
from sage.arith.misc import fundamental_discriminant
29-
from sage.matrix.matrix_space import MatrixSpace
3026
from sage.matrix.constructor import matrix
31-
from sage.rings.integer_ring import ZZ
32-
from sage.rings.rational_field import QQ
33-
from sage.rings.integer import Integer
27+
from sage.matrix.matrix_space import MatrixSpace
28+
from sage.misc.cachefunc import cached_method
29+
from sage.misc.lazy_import import lazy_import
30+
from sage.misc.misc_c import prod
3431
from sage.misc.verbose import verbose
3532
from sage.quadratic_forms.special_values import quadratic_L_function__exact
33+
from sage.rings.integer import Integer
34+
from sage.rings.integer_ring import ZZ
35+
from sage.rings.rational_field import QQ
36+
3637
lazy_import('sage.quadratic_forms.genera.normal_form', '_min_nonsquare')
3738
lazy_import('sage.interfaces.magma', 'magma')
3839

@@ -120,8 +121,7 @@ def genera(sig_pair, determinant, max_scale=None, even=False):
120121
return genera
121122

122123

123-
# #35557: In Python < 3.10, a staticmethod cannot be called directly
124-
_genera_staticmethod = staticmethod(genera)
124+
genera = staticmethod(genera)
125125

126126

127127
def _local_genera(p, rank, det_val, max_scale, even):
@@ -172,8 +172,8 @@ def _local_genera(p, rank, det_val, max_scale, even):
172172
Genus symbol at 5: 5^-2,
173173
Genus symbol at 5: 5^2]
174174
"""
175-
from sage.misc.mrange import cantor_product
176175
from sage.combinat.integer_lists.invlex import IntegerListsLex
176+
from sage.misc.mrange import cantor_product
177177
scales_rks = [] # contains possibilities for scales and ranks
178178
for rkseq in IntegerListsLex(rank, length=max_scale + 1): # rank sequences
179179
# sum(rkseq) = rank
@@ -2871,8 +2871,10 @@ def rational_representative(self):
28712871
[0 0 0 0 0 0 1 0]
28722872
[0 0 0 0 0 0 0 2]
28732873
"""
2874-
from sage.quadratic_forms.quadratic_form import QuadraticForm
2875-
from sage.quadratic_forms.quadratic_form import quadratic_form_from_invariants
2874+
from sage.quadratic_forms.quadratic_form import (
2875+
QuadraticForm,
2876+
quadratic_form_from_invariants,
2877+
)
28762878
sminus = self.signature_pair_of_matrix()[1]
28772879
det = self.determinant()
28782880
m = self.rank()
@@ -2907,7 +2909,10 @@ def _compute_representative(self, LLL=True):
29072909
....: G = genera((2,2), det, even=False)
29082910
....: assert all(g==Genus(g.representative()) for g in G)
29092911
"""
2910-
from sage.modules.free_quadratic_module_integer_symmetric import IntegralLattice, local_modification
2912+
from sage.modules.free_quadratic_module_integer_symmetric import (
2913+
IntegralLattice,
2914+
local_modification,
2915+
)
29112916
q = self.rational_representative()
29122917
# the associated quadratic form xGx.T/2 should be integral
29132918
L = IntegralLattice(4 * q).maximal_overlattice()
@@ -3059,15 +3064,19 @@ def representatives(self, backend=None, algorithm=None):
30593064
if self.signature_pair()[0] == 0:
30603065
e = ZZ(-1)
30613066
d = - 4 * self.determinant()
3062-
from sage.quadratic_forms.binary_qf import BinaryQF_reduced_representatives
3067+
from sage.quadratic_forms.binary_qf import (
3068+
BinaryQF_reduced_representatives,
3069+
)
30633070
for q in BinaryQF_reduced_representatives(d, proper=False):
30643071
if q[1] % 2 == 0: # we want integrality of the gram matrix
30653072
m = e*matrix(ZZ, 2, [q[0], q[1] // 2, q[1] // 2, q[2]])
30663073
if Genus(m) == self:
30673074
representatives.append(m)
30683075
if n > 2:
30693076
from sage.quadratic_forms.quadratic_form import QuadraticForm
3070-
from sage.quadratic_forms.quadratic_form__neighbors import neighbor_iteration
3077+
from sage.quadratic_forms.quadratic_form__neighbors import (
3078+
neighbor_iteration,
3079+
)
30713080
e = ZZ.one()
30723081
if not self.is_even():
30733082
e = ZZ(2)
@@ -3152,10 +3161,10 @@ def _standard_mass(self):
31523161
sage: GS._standard_mass() # needs sage.symbolic
31533162
1/48
31543163
"""
3164+
from sage.functions.gamma import gamma
3165+
from sage.functions.transcendental import zeta
31553166
from sage.symbolic.constants import pi
31563167
from sage.symbolic.ring import SR
3157-
from sage.functions.transcendental import zeta
3158-
from sage.functions.gamma import gamma
31593168
n = self.dimension()
31603169
if n % 2 == 0:
31613170
s = n // 2

0 commit comments

Comments
 (0)