Skip to content

Commit

Permalink
sagemathgh-39091: Replace Python 2 'long' with Python 3 'int'
Browse files Browse the repository at this point in the history
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,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->

URL: sagemath#39091
Reported by: user202729
Reviewer(s): Martin Rubey
  • Loading branch information
Release Manager committed Dec 9, 2024
2 parents b5a1e5d + f398a0f commit 735e308
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 36 deletions.
4 changes: 2 additions & 2 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tarball=configure-VERSION.tar.gz
sha1=ca942ace2e5104f3ae9e57946c8228b0bdb580c5
sha256=99c0a76943170a85d2eb868d72dd673c6b0df529d99b808458bdb3b285dec8fe
sha1=f8beeb7b7f9a902b6eb3f3f38b8d45a91e16e67e
sha256=fcb78f1400aac8dae0f5d1c0e07e8467692a9955a50020f6ae2a297b8ba14eba
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d129e08e85a0c6530fa140dfc04c86ac0b74e05e
34cfa670fddd9efa8b4eef3248d2ea8016bc85a9
11 changes: 4 additions & 7 deletions src/sage/libs/mpmath/ext_main.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,7 @@ cdef class Context:
s = (<mpc>x).re.special
t = (<mpc>x).im.special
return s == S_NAN or t == S_NAN
if type(x) is int or type(x) is long or isinstance(x, Integer) \
or isinstance(x, rationallib.mpq):
if isinstance(x, (int, Integer, rationallib.mpq)):
return False
typ = MPF_set_any(&tmp_opx_re, &tmp_opx_im, x, global_opts, 0)
if typ == 1:
Expand Down Expand Up @@ -622,8 +621,7 @@ cdef class Context:
s = (<mpc>x).re.special
t = (<mpc>x).im.special
return s == S_INF or s == S_NINF or t == S_INF or t == S_NINF
if type(x) is int or type(x) is long or isinstance(x, Integer) \
or isinstance(x, rationallib.mpq):
if isinstance(x, (int, Integer, rationallib.mpq)):
return False
typ = MPF_set_any(&tmp_opx_re, &tmp_opx_im, x, global_opts, 0)
if typ == 1:
Expand Down Expand Up @@ -671,8 +669,7 @@ cdef class Context:
if re == libmp.fzero: return im_normal
if im == libmp.fzero: return re_normal
return re_normal and im_normal
if type(x) is int or type(x) is long or isinstance(x, Integer) \
or isinstance(x, rationallib.mpq):
if isinstance(x, (int, Integer, rationallib.mpq)):
return bool(x)
x = ctx.convert(x)
if hasattr(x, '_mpf_') or hasattr(x, '_mpc_'):
Expand Down Expand Up @@ -708,7 +705,7 @@ cdef class Context:
cdef MPF v
cdef MPF w
cdef int typ
if type(x) is int or type(x) is long or isinstance(x, Integer):
if isinstance(x, (int, Integer)):
return True
if isinstance(x, mpf):
v = (<mpf>x).value
Expand Down
2 changes: 1 addition & 1 deletion src/sage/libs/singular/singular.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ cdef inline number *sa2si_ZZmod(IntegerMod_abstract d, ring *_ring) noexcept:
cdef nMapFunc nMapFuncPtr = NULL

if _ring.cf.type == n_Z2m:
_d = long(d)
_d = d
return nr2mMapZp(<number *>_d, currRing.cf, _ring.cf)
elif _ring.cf.type == n_Zn or _ring.cf.type == n_Znm:
lift = d.lift()
Expand Down
18 changes: 9 additions & 9 deletions src/sage/misc/randstate.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,11 @@ cdef class randstate:

if seed is None:
if use_urandom:
seed = long(binascii.hexlify(os.urandom(16)), 16)
seed = int(binascii.hexlify(os.urandom(16)), 16)
else:
seed = long(time.time() * 256)
seed = int(time.time() * 256)
else:
seed = long(seed)
seed = int(seed)

# If seed==0, leave it at the default seed used by
# gmp_randinit_default()
Expand Down Expand Up @@ -605,9 +605,9 @@ cdef class randstate:
from sage.rings.integer_ring import ZZ
rand = cls()
if seed is None:
rand.seed(long(ZZ.random_element(long(1)<<128)))
rand.seed(int(ZZ.random_element(1<<128)))
else:
rand.seed(long(seed))
rand.seed(int(seed))
self._python_random = rand
return rand

Expand All @@ -624,7 +624,7 @@ cdef class randstate:
48314508034782595865062786044921182484
"""
from sage.rings.integer_ring import ZZ
return ZZ.random_element(long(1)<<128)
return ZZ.random_element(1<<128)

cpdef long_seed(self):
r"""
Expand All @@ -638,7 +638,7 @@ cdef class randstate:
256056279774514099508607350947089272595
"""
from sage.rings.integer_ring import ZZ
return long(ZZ.random_element(long(1)<<128))
return int(ZZ.random_element(1<<128))

cpdef set_seed_libc(self, bint force):
r"""
Expand Down Expand Up @@ -688,7 +688,7 @@ cdef class randstate:
if force or _ntl_seed_randstate is not self:
import sage.libs.ntl.ntl_ZZ as ntl_ZZ
from sage.rings.integer_ring import ZZ
ntl_ZZ.ntl_setSeed(ZZ.random_element(long(1)<<128))
ntl_ZZ.ntl_setSeed(ZZ.random_element(1<<128))
_ntl_seed_randstate = self

def set_seed_gap(self):
Expand All @@ -715,7 +715,7 @@ cdef class randstate:
mersenne_seed, classic_seed = self._gap_saved_seed
else:
from sage.rings.integer_ring import ZZ
seed = ZZ.random_element(long(1)<<128)
seed = ZZ.random_element(1<<128)
classic_seed = seed
mersenne_seed = seed

Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/finite_rings/finite_field_base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ cdef class FiniteField(Field):
False
"""
from sage.rings.integer_ring import ZZ
if R is int or R is long or R is ZZ:
if R is int or R is ZZ:
return True
if isinstance(R, sage.rings.abc.IntegerModRing) and self.characteristic().divides(R.characteristic()):
return R.hom((self.one(),), check=False)
Expand Down
12 changes: 10 additions & 2 deletions src/sage/rings/finite_rings/integer_mod.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2039,8 +2039,12 @@ cdef class IntegerMod_gmp(IntegerMod_abstract):
sage: e = Mod(19, 10^10)
sage: e << 102
9443608576
sage: e << (2^200)
Traceback (most recent call last):
...
OverflowError: Python int too large to convert to C long
"""
return self.shift(long(k))
return self.shift(k)

def __rshift__(IntegerMod_gmp self, k):
r"""
Expand All @@ -2053,8 +2057,12 @@ cdef class IntegerMod_gmp(IntegerMod_abstract):
sage: e = Mod(19, 10^10)
sage: e >> 1
9
sage: e << (2^200)
Traceback (most recent call last):
...
OverflowError: Python int too large to convert to C long
"""
return self.shift(-long(k))
return self.shift(-k)

cdef shift(IntegerMod_gmp self, long k):
r"""
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/integer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement):
mpz_set_pylong(self.value, x)

elif isinstance(x, float):
n = long(x)
n = int(x)
if n == x:
mpz_set_pylong(self.value, n)
else:
Expand Down Expand Up @@ -7434,7 +7434,7 @@ cdef class int_to_Z(Morphism):
def __init__(self):
import sage.categories.homset
from sage.sets.pythonclass import Set_PythonType
Morphism.__init__(self, sage.categories.homset.Hom(Set_PythonType(long), integer_ring.ZZ))
Morphism.__init__(self, sage.categories.homset.Hom(Set_PythonType(int), integer_ring.ZZ))

cpdef Element _call_(self, a):
cdef Integer r
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/padics/relaxed_template.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ cdef class RelaxedElement(pAdicGenericElement):
964*997^4 + 572*997^5 + 124*997^6 + ...
"""
cdef long start
cdef long shift = long(s)
cdef long shift = s
if shift:
if (<RelaxedElement>self)._parent.is_field():
start = -maxordp
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/puiseux_series_ring_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ cdef class PuiseuxSeries(AlgebraElement):
l = l.add_bigoh(prec / d)

self._l = l
self._e = long(abs(e))
self._e = int(abs(e))

def __reduce__(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/rational.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3030,7 +3030,7 @@ cdef class Rational(sage.structure.element.FieldElement):
Convert this rational to a Python ``int``.
This truncates ``self`` if ``self`` has a denominator (which is
consistent with Python's ``long(floats)``).
consistent with Python's ``int(floats)``).
EXAMPLES::
Expand Down Expand Up @@ -4243,7 +4243,7 @@ cdef class int_to_Q(Morphism):
import sage.categories.homset
from sage.sets.pythonclass import Set_PythonType
Morphism.__init__(self, sage.categories.homset.Hom(
Set_PythonType(long), rational_field.QQ))
Set_PythonType(int), rational_field.QQ))

cpdef Element _call_(self, a):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/real_lazy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ cdef class LazyField(Field):
True
"""
if isinstance(R, type):
if R in [int, long]:
if R is int:
from sage.sets.pythonclass import Set_PythonType
return LazyWrapperMorphism(Set_PythonType(R), self)
elif R.is_exact():
Expand Down
4 changes: 1 addition & 3 deletions src/sage/rings/real_mpfi.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -816,9 +816,7 @@ cdef class RealIntervalField_class(sage.rings.abc.RealIntervalField):
prec = self._prec

# Direct and efficient conversions
if S is ZZ or S is QQ:
return True
if S is int or S is long:
if S is ZZ or S is QQ or S is int:
return True
if isinstance(S, RealIntervalField_class):
return (<RealIntervalField_class>S)._prec >= prec
Expand Down
2 changes: 0 additions & 2 deletions src/sage/rings/real_mpfr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,6 @@ cdef class RealField_class(sage.rings.abc.RealField):
return QQtoRR(QQ, self)
elif (S is RDF or S is float) and self._prec <= 53:
return double_toRR(S, self)
elif S is long:
return int_toRR(long, self)
elif S is int:
return int_toRR(int, self)
elif isinstance(S, RealField_class) and S.prec() >= self._prec:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/symbolic/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ cdef class SymbolicRing(sage.rings.abc.SymbolicRing):
True
"""
if isinstance(R, type):
if R in [int, float, long, complex, bool]:
if R in (int, float, complex, bool):
return True

if is_numpy_type(R):
Expand Down

0 comments on commit 735e308

Please sign in to comment.