Skip to content

Commit 4796e74

Browse files
author
Release Manager
committed
gh-37420: Remove long/int relic in py2, long and int were different types. In py3, only int remains, with long a synonym in cython. <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> <!-- 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". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [ ] The title is concise, informative, and self-explanatory. - [ ] 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 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: #37420 Reported by: nbruin Reviewer(s): grhkm21
2 parents 7b13a0a + 18ace4e commit 4796e74

File tree

3 files changed

+1
-87
lines changed

3 files changed

+1
-87
lines changed

src/sage/rings/integer.pxd

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,3 @@ cdef inline Integer _Integer_from_mpz(mpz_t e) noexcept:
4242
cdef Integer z = Integer.__new__(Integer)
4343
mpz_set(z.value, e)
4444
return z
45-
46-
cdef class int_to_Z(Morphism):
47-
pass

src/sage/rings/integer.pyx

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -7424,87 +7424,6 @@ def make_integer(s):
74247424

74257425

74267426
cdef class int_to_Z(Morphism):
7427-
"""
7428-
Morphism from Python ints to Sage integers.
7429-
7430-
EXAMPLES::
7431-
7432-
sage: f = ZZ.coerce_map_from(int)
7433-
sage: type(f)
7434-
<class 'sage.rings.integer.long_to_Z'>
7435-
sage: f(5r)
7436-
5
7437-
sage: type(f(5r))
7438-
<class 'sage.rings.integer.Integer'>
7439-
sage: 1 + 2r
7440-
3
7441-
sage: type(1 + 2r)
7442-
<class 'sage.rings.integer.Integer'>
7443-
7444-
This is intended for internal use by the coercion system,
7445-
to facilitate fast expressions mixing ints and more complex
7446-
Python types. Note that (as with all morphisms) the input
7447-
is forcably coerced to the domain ``int`` if it is not
7448-
already of the correct type which may have undesirable results::
7449-
7450-
sage: f.domain()
7451-
Set of Python objects of class 'int'
7452-
sage: f(1/3)
7453-
0
7454-
sage: f(1.7)
7455-
1
7456-
sage: f("10")
7457-
10
7458-
7459-
A pool is used for small integers::
7460-
7461-
sage: f(10) is f(10)
7462-
True
7463-
sage: f(-2) is f(-2)
7464-
True
7465-
"""
7466-
7467-
def __init__(self):
7468-
"""
7469-
TESTS::
7470-
7471-
sage: f = ZZ.coerce_map_from(int)
7472-
sage: f.parent()
7473-
Set of Morphisms from Set of Python objects of class 'int' to Integer Ring in Category of sets
7474-
"""
7475-
import sage.categories.homset
7476-
from sage.sets.pythonclass import Set_PythonType
7477-
Morphism.__init__(self, sage.categories.homset.Hom(Set_PythonType(int), integer_ring.ZZ))
7478-
7479-
cpdef Element _call_(self, a) noexcept:
7480-
"""
7481-
Return a new integer with the same value as ``a``.
7482-
7483-
TESTS::
7484-
7485-
sage: f = ZZ.coerce_map_from(int)
7486-
sage: f(100r)
7487-
100
7488-
"""
7489-
if type(a) is not int:
7490-
raise TypeError("must be a Python int object")
7491-
7492-
return smallInteger(PyLong_AsLong(a))
7493-
7494-
def _repr_type(self):
7495-
"""
7496-
TESTS::
7497-
7498-
sage: f = ZZ.coerce_map_from(int)
7499-
sage: print(f)
7500-
Native morphism:
7501-
From: Set of Python objects of class 'int'
7502-
To: Integer Ring
7503-
"""
7504-
return "Native"
7505-
7506-
7507-
cdef class long_to_Z(Morphism):
75087427
"""
75097428
EXAMPLES::
75107429

src/sage/rings/integer_ring.pyx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain):
586586
sage: f(-7r)
587587
-7
588588
"""
589-
if S is long:
590-
return sage.rings.integer.long_to_Z()
591-
elif S is int:
589+
if S is int:
592590
return sage.rings.integer.int_to_Z()
593591
elif S is bool:
594592
return True

0 commit comments

Comments
 (0)