Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleaning some things remaining from python 2 #35792

Merged
merged 1 commit into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/doc/fr/tutorial/afterword.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ Aussi, Sage se comporte diffΓ©remment de Python Γ  plusieurs Γ©gards.
sage: a
10

- **Division entière :** L'expression Python ``2/3`` ne se comporte pas
de la manière à laquelle s'attendraient des mathématiciens. En Python 2, si
``m`` et ``n`` sont de type int, alors ``m/n`` est aussi de type int, c'est
le quotient entier de ``m`` par ``n``. Par consΓ©quent, ``2/3=0``. Ce
comportement est diffΓ©rent en Python 3, oΓΉ ``2/3`` renvoie un flottant
``0.6666...`` et c'est ``2//3`` qui renvoie ``0``.
- **Division entière :** L'expression Python ``2/3`` ne se comporte
pas de la manière à laquelle s'attendraient des mathématiciens. En
Python 3, si ``m`` et ``n`` sont de type ``int``, alors ``m/n`` est
de type ``float``, c'est le quotient rΓ©el de ``m`` par ``n``. Par
exemple, ``2/3`` renvoie ``0.6666...``. Pour obtenir le quotient
entier, il faut utiliser ``2//3`` qui renvoie ``0``.

Dans l'interprΓ©teur Sage, nous rΓ©glons cela en encapsulant
automatiquement les entiers litΓ©raux par ``Integer( )`` et en faisant
Expand Down
10 changes: 2 additions & 8 deletions src/sage/combinat/tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@
the function ``sum`` receives the iterator directly, and can
short-circuit the construction of the intermediate list. If there are a
large number of elements, this avoids allocating a large quantity of
memory to fill a list which will be immediately destroyed [2]_.
memory to fill a list which will be immediately destroyed.

Most functions that take a list of elements as input will also accept
an iterator (or an iterable) instead. To begin with, one can obtain the
Expand Down Expand Up @@ -1805,7 +1805,7 @@
then the graphs with two edges, and so on. The set of children of a
graph `G` can be constructed by *augmentation*, adding an edge in all
the possible ways to `G`, and then selecting, from among those graphs,
the ones that are still canonical [3]_. Recursively, one obtains all
the ones that are still canonical [2]_. Recursively, one obtains all
the canonical graphs.

.. figure:: ../../media/prefix-tree-graphs-4.png
Expand Down Expand Up @@ -1848,12 +1848,6 @@
clean up.

.. [2]
Technical detail: ``range`` returns an iterator on
`\{0,\dots,8\}` while ``range`` returns the corresponding
list. Starting in ``Python`` 3.0, ``range`` will behave like ``range``, and
``range`` will no longer be needed.

.. [3]
In practice, an efficient implementation would exploit the symmetries
of `G`, i.e., its automorphism group, to reduce the number of
children to explore, and to reduce the cost of each test of
Expand Down
4 changes: 2 additions & 2 deletions src/sage/databases/findstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2095,7 +2095,7 @@ def oeis_search(self, search_size=32, verbose=True):
if counter >= 4:
if verbose:
print('Searching the OEIS for "%s"' % OEIS_string)
return oeis(str(OEIS_string)) # in python 2.7, oeis does not like unicode
return oeis(OEIS_string)

if verbose:
print("Too little information to search the OEIS for this statistic (only %s values given)." % counter)
Expand Down Expand Up @@ -2371,7 +2371,7 @@ def submit(self, max_values=FINDSTAT_MAX_SUBMISSION_VALUES):
sage: s.set_description(u"MΓΆbius") # optional -- internet
sage: s.submit() # optional -- webbrowser
"""
args = dict()
args = {}
args["OriginalStatistic"] = self.id_str()
args["Domain"] = self.domain().id_str()
args["Values"] = self.first_terms_str(max_values=max_values)
Expand Down
57 changes: 3 additions & 54 deletions src/sage/rings/rational.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4187,7 +4187,7 @@ cdef class Q_to_Z(Map):

cdef class int_to_Q(Morphism):
r"""
A morphism from Python 2 ``int`` to `\QQ`.
A morphism from Python 3 ``int`` to `\QQ`.
"""
def __init__(self):
"""
Expand All @@ -4203,57 +4203,6 @@ cdef class int_to_Q(Morphism):
from . import rational_field
import sage.categories.homset
from sage.sets.pythonclass import Set_PythonType
Morphism.__init__(self, sage.categories.homset.Hom(Set_PythonType(int), rational_field.QQ))

cpdef Element _call_(self, a):
"""
Return the image of the morphism on ``a``.

EXAMPLES::

sage: f = sage.rings.rational.int_to_Q()
sage: f(int(4)) # indirect doctest
4
"""
cdef Rational rat

if type(a) is not int:
raise TypeError("must be a Python int object")

rat = <Rational> Rational.__new__(Rational)
mpq_set_si(rat.value, PyInt_AS_LONG(a), 1)
return rat

def _repr_type(self):
"""
Return string that describes the type of morphism.

EXAMPLES::

sage: sage.rings.rational.int_to_Q()._repr_type()
'Native'
"""
return "Native"


cdef class long_to_Q(Morphism):
r"""
A morphism from Python 2 ``long``/Python 3 ``int`` to `\QQ`.
"""
def __init__(self):
"""
Initialize ``self``.

EXAMPLES::

sage: sage.rings.rational.long_to_Q()
Native morphism:
From: Set of Python objects of class 'int'
To: Rational Field
"""
from . import rational_field
import sage.categories.homset
from sage.sets.pythonclass import Set_PythonType
Morphism.__init__(self, sage.categories.homset.Hom(
Set_PythonType(long), rational_field.QQ))

Expand All @@ -4263,7 +4212,7 @@ cdef class long_to_Q(Morphism):

EXAMPLES::

sage: f = sage.rings.rational.long_to_Q()
sage: f = sage.rings.rational.int_to_Q()
sage: f(4^100)
1606938044258990275541962092341162602522202993782792835301376
"""
Expand All @@ -4289,7 +4238,7 @@ cdef class long_to_Q(Morphism):

EXAMPLES::

sage: sage.rings.rational.long_to_Q()._repr_type()
sage: sage.rings.rational.int_to_Q()._repr_type()
'Native'
"""
return "Native"
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/rational_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def _coerce_map_from_(self, S):
if S is ZZ:
return rational.Z_to_Q()
elif S is int:
return rational.long_to_Q()
return rational.int_to_Q()
elif ZZ.has_coerce_map_from(S):
return rational.Z_to_Q() * ZZ._internal_coerce_map_from(S)
from sage.rings.localization import Localization
Expand Down
7 changes: 1 addition & 6 deletions src/sage/structure/sage_object.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ cdef class SageObject:
if hasattr(self, '__custom_name'):
del self.__custom_name


def __repr__(self):
"""
Default method for string representation.
Expand Down Expand Up @@ -191,11 +190,7 @@ cdef class SageObject:
reprfunc = self._repr_
except AttributeError:
return super().__repr__()
result = reprfunc()
if isinstance(result, str):
return result
# Allow _repr_ to return unicode on Python 2
return result.encode('utf-8')
return reprfunc()

def _ascii_art_(self):
r"""
Expand Down