Skip to content

Commit 2059f42

Browse files
author
Release Manager
committed
gh-39091: Replace Python 2 'long' with Python 3 'int' After Cython commit cython/cython@d0f53f40f8c1 8da747919449febc2344ebb43e5f , `long` is no longer valid in `.pyx` file. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] 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: #39091 Reported by: user202729 Reviewer(s): Martin Rubey
2 parents fb7f19a + f398a0f commit 2059f42

File tree

13 files changed

+34
-33
lines changed

13 files changed

+34
-33
lines changed

src/sage/libs/mpmath/ext_main.pyx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,7 @@ cdef class Context:
580580
s = (<mpc>x).re.special
581581
t = (<mpc>x).im.special
582582
return s == S_NAN or t == S_NAN
583-
if type(x) is int or type(x) is long or isinstance(x, Integer) \
584-
or isinstance(x, rationallib.mpq):
583+
if isinstance(x, (int, Integer, rationallib.mpq)):
585584
return False
586585
typ = MPF_set_any(&tmp_opx_re, &tmp_opx_im, x, global_opts, 0)
587586
if typ == 1:
@@ -622,8 +621,7 @@ cdef class Context:
622621
s = (<mpc>x).re.special
623622
t = (<mpc>x).im.special
624623
return s == S_INF or s == S_NINF or t == S_INF or t == S_NINF
625-
if type(x) is int or type(x) is long or isinstance(x, Integer) \
626-
or isinstance(x, rationallib.mpq):
624+
if isinstance(x, (int, Integer, rationallib.mpq)):
627625
return False
628626
typ = MPF_set_any(&tmp_opx_re, &tmp_opx_im, x, global_opts, 0)
629627
if typ == 1:
@@ -671,8 +669,7 @@ cdef class Context:
671669
if re == libmp.fzero: return im_normal
672670
if im == libmp.fzero: return re_normal
673671
return re_normal and im_normal
674-
if type(x) is int or type(x) is long or isinstance(x, Integer) \
675-
or isinstance(x, rationallib.mpq):
672+
if isinstance(x, (int, Integer, rationallib.mpq)):
676673
return bool(x)
677674
x = ctx.convert(x)
678675
if hasattr(x, '_mpf_') or hasattr(x, '_mpc_'):
@@ -708,7 +705,7 @@ cdef class Context:
708705
cdef MPF v
709706
cdef MPF w
710707
cdef int typ
711-
if type(x) is int or type(x) is long or isinstance(x, Integer):
708+
if isinstance(x, (int, Integer)):
712709
return True
713710
if isinstance(x, mpf):
714711
v = (<mpf>x).value

src/sage/libs/singular/singular.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ cdef inline number *sa2si_ZZmod(IntegerMod_abstract d, ring *_ring) noexcept:
15351535
cdef nMapFunc nMapFuncPtr = NULL
15361536

15371537
if _ring.cf.type == n_Z2m:
1538-
_d = long(d)
1538+
_d = d
15391539
return nr2mMapZp(<number *>_d, currRing.cf, _ring.cf)
15401540
elif _ring.cf.type == n_Zn or _ring.cf.type == n_Znm:
15411541
lift = d.lift()

src/sage/misc/randstate.pyx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,11 @@ cdef class randstate:
529529

530530
if seed is None:
531531
if use_urandom:
532-
seed = long(binascii.hexlify(os.urandom(16)), 16)
532+
seed = int(binascii.hexlify(os.urandom(16)), 16)
533533
else:
534-
seed = long(time.time() * 256)
534+
seed = int(time.time() * 256)
535535
else:
536-
seed = long(seed)
536+
seed = int(seed)
537537

538538
# If seed==0, leave it at the default seed used by
539539
# gmp_randinit_default()
@@ -605,9 +605,9 @@ cdef class randstate:
605605
from sage.rings.integer_ring import ZZ
606606
rand = cls()
607607
if seed is None:
608-
rand.seed(long(ZZ.random_element(long(1)<<128)))
608+
rand.seed(int(ZZ.random_element(1<<128)))
609609
else:
610-
rand.seed(long(seed))
610+
rand.seed(int(seed))
611611
self._python_random = rand
612612
return rand
613613

@@ -624,7 +624,7 @@ cdef class randstate:
624624
48314508034782595865062786044921182484
625625
"""
626626
from sage.rings.integer_ring import ZZ
627-
return ZZ.random_element(long(1)<<128)
627+
return ZZ.random_element(1<<128)
628628

629629
cpdef long_seed(self):
630630
r"""
@@ -638,7 +638,7 @@ cdef class randstate:
638638
256056279774514099508607350947089272595
639639
"""
640640
from sage.rings.integer_ring import ZZ
641-
return long(ZZ.random_element(long(1)<<128))
641+
return int(ZZ.random_element(1<<128))
642642

643643
cpdef set_seed_libc(self, bint force):
644644
r"""
@@ -688,7 +688,7 @@ cdef class randstate:
688688
if force or _ntl_seed_randstate is not self:
689689
import sage.libs.ntl.ntl_ZZ as ntl_ZZ
690690
from sage.rings.integer_ring import ZZ
691-
ntl_ZZ.ntl_setSeed(ZZ.random_element(long(1)<<128))
691+
ntl_ZZ.ntl_setSeed(ZZ.random_element(1<<128))
692692
_ntl_seed_randstate = self
693693

694694
def set_seed_gap(self):
@@ -715,7 +715,7 @@ cdef class randstate:
715715
mersenne_seed, classic_seed = self._gap_saved_seed
716716
else:
717717
from sage.rings.integer_ring import ZZ
718-
seed = ZZ.random_element(long(1)<<128)
718+
seed = ZZ.random_element(1<<128)
719719
classic_seed = seed
720720
mersenne_seed = seed
721721

src/sage/rings/finite_rings/finite_field_base.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ cdef class FiniteField(Field):
13581358
False
13591359
"""
13601360
from sage.rings.integer_ring import ZZ
1361-
if R is int or R is long or R is ZZ:
1361+
if R is int or R is ZZ:
13621362
return True
13631363
if isinstance(R, sage.rings.abc.IntegerModRing) and self.characteristic().divides(R.characteristic()):
13641364
return R.hom((self.one(),), check=False)

src/sage/rings/finite_rings/integer_mod.pyx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,8 +2039,12 @@ cdef class IntegerMod_gmp(IntegerMod_abstract):
20392039
sage: e = Mod(19, 10^10)
20402040
sage: e << 102
20412041
9443608576
2042+
sage: e << (2^200)
2043+
Traceback (most recent call last):
2044+
...
2045+
OverflowError: Python int too large to convert to C long
20422046
"""
2043-
return self.shift(long(k))
2047+
return self.shift(k)
20442048

20452049
def __rshift__(IntegerMod_gmp self, k):
20462050
r"""
@@ -2053,8 +2057,12 @@ cdef class IntegerMod_gmp(IntegerMod_abstract):
20532057
sage: e = Mod(19, 10^10)
20542058
sage: e >> 1
20552059
9
2060+
sage: e << (2^200)
2061+
Traceback (most recent call last):
2062+
...
2063+
OverflowError: Python int too large to convert to C long
20562064
"""
2057-
return self.shift(-long(k))
2065+
return self.shift(-k)
20582066

20592067
cdef shift(IntegerMod_gmp self, long k):
20602068
r"""

src/sage/rings/integer.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement):
645645
mpz_set_pylong(self.value, x)
646646

647647
elif isinstance(x, float):
648-
n = long(x)
648+
n = int(x)
649649
if n == x:
650650
mpz_set_pylong(self.value, n)
651651
else:
@@ -7434,7 +7434,7 @@ cdef class int_to_Z(Morphism):
74347434
def __init__(self):
74357435
import sage.categories.homset
74367436
from sage.sets.pythonclass import Set_PythonType
7437-
Morphism.__init__(self, sage.categories.homset.Hom(Set_PythonType(long), integer_ring.ZZ))
7437+
Morphism.__init__(self, sage.categories.homset.Hom(Set_PythonType(int), integer_ring.ZZ))
74387438

74397439
cpdef Element _call_(self, a):
74407440
cdef Integer r

src/sage/rings/padics/relaxed_template.pxi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1659,7 +1659,7 @@ cdef class RelaxedElement(pAdicGenericElement):
16591659
964*997^4 + 572*997^5 + 124*997^6 + ...
16601660
"""
16611661
cdef long start
1662-
cdef long shift = long(s)
1662+
cdef long shift = s
16631663
if shift:
16641664
if (<RelaxedElement>self)._parent.is_field():
16651665
start = -maxordp

src/sage/rings/puiseux_series_ring_element.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ cdef class PuiseuxSeries(AlgebraElement):
201201
l = l.add_bigoh(prec / d)
202202

203203
self._l = l
204-
self._e = long(abs(e))
204+
self._e = int(abs(e))
205205

206206
def __reduce__(self):
207207
"""

src/sage/rings/rational.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3030,7 +3030,7 @@ cdef class Rational(sage.structure.element.FieldElement):
30303030
Convert this rational to a Python ``int``.
30313031
30323032
This truncates ``self`` if ``self`` has a denominator (which is
3033-
consistent with Python's ``long(floats)``).
3033+
consistent with Python's ``int(floats)``).
30343034
30353035
EXAMPLES::
30363036
@@ -4243,7 +4243,7 @@ cdef class int_to_Q(Morphism):
42434243
import sage.categories.homset
42444244
from sage.sets.pythonclass import Set_PythonType
42454245
Morphism.__init__(self, sage.categories.homset.Hom(
4246-
Set_PythonType(long), rational_field.QQ))
4246+
Set_PythonType(int), rational_field.QQ))
42474247

42484248
cpdef Element _call_(self, a):
42494249
"""

src/sage/rings/real_lazy.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ cdef class LazyField(Field):
174174
True
175175
"""
176176
if isinstance(R, type):
177-
if R in [int, long]:
177+
if R is int:
178178
from sage.sets.pythonclass import Set_PythonType
179179
return LazyWrapperMorphism(Set_PythonType(R), self)
180180
elif R.is_exact():

0 commit comments

Comments
 (0)