Skip to content

Commit bbf5695

Browse files
author
Release Manager
committed
gh-35594: Remove some circular imports in `sage.rings`, `sage.symbolic` <!-- Please provide a concise, informative and self-explanatory title. --> <!-- Don't put issue numbers in the title. Put it in the Description below. --> <!-- For example, instead of "Fixes #12345", use "Add a new method to multiply two integers" --> ### 📚 Description <!-- Describe your changes here in detail. --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> Fixes #35580. <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x ]`. --> - [x] The title is concise, informative, and self-explanatory. - [ ] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #35594 Reported by: Matthias Köppe Reviewer(s): Dima Pasechnik
2 parents 2152954 + 69df1ef commit bbf5695

File tree

19 files changed

+83
-60
lines changed

19 files changed

+83
-60
lines changed

src/.relint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
namespace package. Type import_statements("SOME_IDENTIFIER") to find a more specific import,
5050
or use 'sage --fiximports' to fix automatically in the source file.
5151
# Keep in sync with SAGE_ROOT/src/sage/misc/replace_dot_all.py
52-
pattern: 'from\s+sage(|[.](arith|categories|combinat|crypto|databases|data_structures|dynamics|ext|game_theory|games|graphs|groups|interfaces|manifolds|matrix|matroids|misc|modules|monoids|numerical|probability|quadratic_forms|quivers|rings|sat|schemes|sets|stats|tensor)[a-z0-9_.]*|[.]libs)[.]all\s+import'
52+
pattern: 'from\s+sage(|[.](arith|categories|combinat|crypto|databases|data_structures|dynamics|ext|game_theory|games|graphs|groups|interfaces|manifolds|matrix|matroids|misc|modules|monoids|numerical|probability|quadratic_forms|quivers|rings|sat|schemes|sets|stats|symbolic|tensor)[a-z0-9_.]*|[.]libs)[.]all\s+import'
5353
# imports from .all are allowed in all.py; also allow in some modules that need sage.all
5454
filePattern: '(.*/|)(?!(all|benchmark|dev_tools|parsing|sage_eval))[^/.]*[.](py|pyx|pxi)$'
5555

src/sage/categories/classical_crystals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def demazure_character(self, w, f=None):
180180
u = self.algebra(ZZ).sum_of_monomials(self.module_generators)
181181
u = self.demazure_operator(u, word)
182182
if f is None:
183-
from sage.symbolic.all import SR as P
183+
from sage.symbolic.ring import SR as P
184184
x = [P.var('x%s' % (i+1)) for i in range(n)]
185185
# TODO: use P.linear_combination when PolynomialRing will be a ModulesWithBasis
186186
return sum((coeff*prod((x[i]**(c.weight()[i]) for i in range(n)), P.one()) for c, coeff in u), P.zero())

src/sage/functions/error.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@
4646
from sage.symbolic.expression import Expression
4747
from sage.functions.all import exp
4848
from sage.misc.functional import sqrt
49-
from sage.symbolic.constants import pi
49+
from sage.symbolic.constants import I, pi
5050
from sage.rings.rational import Rational
5151
from sage.rings.infinity import unsigned_infinity
52-
from sage.symbolic.expression import I
52+
5353

5454
class Function_erf(BuiltinFunction):
5555
r"""

src/sage/misc/functional.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,8 +1881,7 @@ def _do_sqrt(x, prec=None, extend=True, all=False):
18811881
from sage.rings.complex_mpfr import ComplexField
18821882
return ComplexField(prec)(x).sqrt(all=all)
18831883
if x == -1:
1884-
from sage.symbolic.expression import I
1885-
z = I
1884+
from sage.symbolic.constants import I as z
18861885
else:
18871886
from sage.symbolic.ring import SR
18881887
z = SR(x).sqrt()

src/sage/modular/modform_hecketriangle/element.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def lseries(self, num_prec=None, max_imaginary_part=0, max_asymp_coeffs=40):
285285
-23.9781792831...
286286
"""
287287
from sage.rings.integer_ring import ZZ
288-
from sage.symbolic.all import pi
288+
from sage.symbolic.constants import pi
289289
from sage.misc.functional import sqrt
290290
from sage.lfunctions.dokchitser import Dokchitser
291291

src/sage/modules/vector_symbolic_dense.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
#*****************************************************************************
5656

5757
from . import free_module_element
58-
from sage.symbolic.all import Expression
58+
from sage.symbolic.expression import Expression
5959

6060

6161
def apply_map(phi):

src/sage/rings/infinity.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,17 @@
216216
#*****************************************************************************
217217

218218
from sys import maxsize
219+
220+
import sage.rings.abc
221+
222+
from sage.misc.fast_methods import Singleton
223+
from sage.misc.lazy_import import lazy_import
219224
from sage.rings.ring import Ring
220225
from sage.structure.element import RingElement, InfinityElement
221226
from sage.structure.richcmp import rich_to_bool, richcmp
222-
from sage.misc.fast_methods import Singleton
223-
import sage.rings.abc
224-
import sage.rings.integer
225-
import sage.rings.rational
226227

227-
import sage.rings.integer_ring
228+
lazy_import('sage.rings.integer', 'Integer')
229+
228230

229231
_obj = {}
230232
class _uniq():
@@ -327,12 +329,11 @@ def __pari__(self):
327329
sage: pari(oo)
328330
+oo
329331
"""
330-
# For some reason, it seems problematic to import sage.libs.all.pari,
331-
# so we call it directly.
332+
from sage.libs.pari.all import pari
332333
if self._sign >= 0:
333-
return sage.libs.all.pari('oo')
334+
return pari('oo')
334335
else:
335-
return sage.libs.all.pari('-oo')
336+
return pari('-oo')
336337

337338
def _latex_(self):
338339
r"""
@@ -850,7 +851,7 @@ def _div_(self, other):
850851
0
851852
"""
852853
if isinstance(other, UnsignedInfinity):
853-
return sage.rings.integer_ring.ZZ(0)
854+
return Integer(0)
854855
raise ValueError("quotient of number < oo by number < oo not defined")
855856

856857
def _richcmp_(self, other, op):
@@ -1390,7 +1391,7 @@ def _mul_(self, other):
13901391
if other.is_zero():
13911392
if isinstance(self, InfinityElement):
13921393
raise SignError("cannot multiply infinity by zero")
1393-
return sage.rings.integer_ring.ZZ(0)
1394+
return Integer(0)
13941395
if self.value < 0:
13951396
if isinstance(other, InfinityElement):
13961397
return -other
@@ -1402,7 +1403,7 @@ def _mul_(self, other):
14021403
if self.value == 0:
14031404
if isinstance(other, InfinityElement):
14041405
raise SignError("cannot multiply infinity by zero")
1405-
return sage.rings.integer_ring.ZZ(0)
1406+
return Integer(0)
14061407

14071408
def _div_(self, other):
14081409
"""

src/sage/rings/number_field/number_field.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8285,7 +8285,8 @@ def _coerce_map_from_(self, R):
82858285
sage: K.coerce(sqrt(2))
82868286
Traceback (most recent call last):
82878287
...
8288-
TypeError: no canonical coercion from Symbolic Ring to Number Field in a with defining polynomial x^2 - 2 with a = 1.414213562373095?
8288+
TypeError: no canonical coercion from Symbolic Ring to Number Field in a
8289+
with defining polynomial x^2 - 2 with a = 1.414213562373095?
82898290
82908291
TESTS::
82918292

src/sage/rings/polynomial/polynomial_element.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8234,7 +8234,7 @@ cdef class Polynomial(CommutativePolynomial):
82348234
if isinstance(L, sage.rings.abc.SymbolicRing):
82358235
if self.degree() == 2:
82368236
from sage.misc.functional import sqrt
8237-
from sage.symbolic.expression import I
8237+
from sage.symbolic.constants import I
82388238
coeffs = self.list()
82398239
D = coeffs[1]*coeffs[1] - 4*coeffs[0]*coeffs[2]
82408240
l = None

src/sage/rings/real_mpfr.pyx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,6 @@ from .rational cimport Rational
153153

154154
from sage.categories.map cimport Map
155155

156-
cdef ZZ, QQ, RDF
157-
from .integer_ring import ZZ
158-
from .rational_field import QQ
159-
from .real_double import RDF
160156
from .real_double cimport RealDoubleElement
161157

162158
import sage.rings.rational_field
@@ -729,6 +725,10 @@ cdef class RealField_class(sage.rings.abc.RealField):
729725
sage: R.get_action(ZZ)
730726
Right scalar multiplication by Integer Ring on Univariate Polynomial Ring in x over Real Field with 53 bits of precision
731727
"""
728+
from .integer_ring import ZZ
729+
from .rational_field import QQ
730+
from .real_double import RDF
731+
732732
if S is ZZ:
733733
return ZZtoRR(ZZ, self)
734734
elif S is QQ:
@@ -1872,6 +1872,8 @@ cdef class RealNumber(sage.structure.element.RingElement):
18721872
sage: RealField(100)(2).imag()
18731873
0
18741874
"""
1875+
from .integer_ring import ZZ
1876+
18751877
return ZZ(0)
18761878

18771879
def str(self, int base=10, size_t digits=0, *, no_sci=None,

0 commit comments

Comments
 (0)