Skip to content

Commit 41d8113

Browse files
author
Release Manager
committed
gh-35792: cleaning some things remaining from python 2 <!-- 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 this is making some little changes, both in code and doc, related to the transition py2 to py3 <!-- 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. 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. - [ ] 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: #35792 Reported by: Frédéric Chapoton Reviewer(s): Matthias Köppe
2 parents fb0ae66 + 9f4a294 commit 41d8113

File tree

6 files changed

+15
-77
lines changed

6 files changed

+15
-77
lines changed

src/doc/fr/tutorial/afterword.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ Aussi, Sage se comporte différemment de Python à plusieurs égards.
112112
sage: a
113113
10
114114

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

122122
Dans l'interpréteur Sage, nous réglons cela en encapsulant
123123
automatiquement les entiers litéraux par ``Integer( )`` et en faisant

src/sage/combinat/tutorial.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@
10481048
the function ``sum`` receives the iterator directly, and can
10491049
short-circuit the construction of the intermediate list. If there are a
10501050
large number of elements, this avoids allocating a large quantity of
1051-
memory to fill a list which will be immediately destroyed [2]_.
1051+
memory to fill a list which will be immediately destroyed.
10521052
10531053
Most functions that take a list of elements as input will also accept
10541054
an iterator (or an iterable) instead. To begin with, one can obtain the
@@ -1805,7 +1805,7 @@
18051805
then the graphs with two edges, and so on. The set of children of a
18061806
graph `G` can be constructed by *augmentation*, adding an edge in all
18071807
the possible ways to `G`, and then selecting, from among those graphs,
1808-
the ones that are still canonical [3]_. Recursively, one obtains all
1808+
the ones that are still canonical [2]_. Recursively, one obtains all
18091809
the canonical graphs.
18101810
18111811
.. figure:: ../../media/prefix-tree-graphs-4.png
@@ -1848,12 +1848,6 @@
18481848
clean up.
18491849
18501850
.. [2]
1851-
Technical detail: ``range`` returns an iterator on
1852-
`\{0,\dots,8\}` while ``range`` returns the corresponding
1853-
list. Starting in ``Python`` 3.0, ``range`` will behave like ``range``, and
1854-
``range`` will no longer be needed.
1855-
1856-
.. [3]
18571851
In practice, an efficient implementation would exploit the symmetries
18581852
of `G`, i.e., its automorphism group, to reduce the number of
18591853
children to explore, and to reduce the cost of each test of

src/sage/databases/findstat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,7 @@ def oeis_search(self, search_size=32, verbose=True):
20952095
if counter >= 4:
20962096
if verbose:
20972097
print('Searching the OEIS for "%s"' % OEIS_string)
2098-
return oeis(str(OEIS_string)) # in python 2.7, oeis does not like unicode
2098+
return oeis(OEIS_string)
20992099

21002100
if verbose:
21012101
print("Too little information to search the OEIS for this statistic (only %s values given)." % counter)
@@ -2371,7 +2371,7 @@ def submit(self, max_values=FINDSTAT_MAX_SUBMISSION_VALUES):
23712371
sage: s.set_description(u"Möbius") # optional -- internet
23722372
sage: s.submit() # optional -- webbrowser
23732373
"""
2374-
args = dict()
2374+
args = {}
23752375
args["OriginalStatistic"] = self.id_str()
23762376
args["Domain"] = self.domain().id_str()
23772377
args["Values"] = self.first_terms_str(max_values=max_values)

src/sage/rings/rational.pyx

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4187,7 +4187,7 @@ cdef class Q_to_Z(Map):
41874187

41884188
cdef class int_to_Q(Morphism):
41894189
r"""
4190-
A morphism from Python 2 ``int`` to `\QQ`.
4190+
A morphism from Python 3 ``int`` to `\QQ`.
41914191
"""
41924192
def __init__(self):
41934193
"""
@@ -4203,57 +4203,6 @@ cdef class int_to_Q(Morphism):
42034203
from . import rational_field
42044204
import sage.categories.homset
42054205
from sage.sets.pythonclass import Set_PythonType
4206-
Morphism.__init__(self, sage.categories.homset.Hom(Set_PythonType(int), rational_field.QQ))
4207-
4208-
cpdef Element _call_(self, a):
4209-
"""
4210-
Return the image of the morphism on ``a``.
4211-
4212-
EXAMPLES::
4213-
4214-
sage: f = sage.rings.rational.int_to_Q()
4215-
sage: f(int(4)) # indirect doctest
4216-
4
4217-
"""
4218-
cdef Rational rat
4219-
4220-
if type(a) is not int:
4221-
raise TypeError("must be a Python int object")
4222-
4223-
rat = <Rational> Rational.__new__(Rational)
4224-
mpq_set_si(rat.value, PyInt_AS_LONG(a), 1)
4225-
return rat
4226-
4227-
def _repr_type(self):
4228-
"""
4229-
Return string that describes the type of morphism.
4230-
4231-
EXAMPLES::
4232-
4233-
sage: sage.rings.rational.int_to_Q()._repr_type()
4234-
'Native'
4235-
"""
4236-
return "Native"
4237-
4238-
4239-
cdef class long_to_Q(Morphism):
4240-
r"""
4241-
A morphism from Python 2 ``long``/Python 3 ``int`` to `\QQ`.
4242-
"""
4243-
def __init__(self):
4244-
"""
4245-
Initialize ``self``.
4246-
4247-
EXAMPLES::
4248-
4249-
sage: sage.rings.rational.long_to_Q()
4250-
Native morphism:
4251-
From: Set of Python objects of class 'int'
4252-
To: Rational Field
4253-
"""
4254-
from . import rational_field
4255-
import sage.categories.homset
4256-
from sage.sets.pythonclass import Set_PythonType
42574206
Morphism.__init__(self, sage.categories.homset.Hom(
42584207
Set_PythonType(long), rational_field.QQ))
42594208

@@ -4263,7 +4212,7 @@ cdef class long_to_Q(Morphism):
42634212
42644213
EXAMPLES::
42654214
4266-
sage: f = sage.rings.rational.long_to_Q()
4215+
sage: f = sage.rings.rational.int_to_Q()
42674216
sage: f(4^100)
42684217
1606938044258990275541962092341162602522202993782792835301376
42694218
"""
@@ -4289,7 +4238,7 @@ cdef class long_to_Q(Morphism):
42894238
42904239
EXAMPLES::
42914240
4292-
sage: sage.rings.rational.long_to_Q()._repr_type()
4241+
sage: sage.rings.rational.int_to_Q()._repr_type()
42934242
'Native'
42944243
"""
42954244
return "Native"

src/sage/rings/rational_field.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def _coerce_map_from_(self, S):
374374
if S is ZZ:
375375
return rational.Z_to_Q()
376376
elif S is int:
377-
return rational.long_to_Q()
377+
return rational.int_to_Q()
378378
elif ZZ.has_coerce_map_from(S):
379379
return rational.Z_to_Q() * ZZ._internal_coerce_map_from(S)
380380
from sage.rings.localization import Localization

src/sage/structure/sage_object.pyx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ cdef class SageObject:
141141
if hasattr(self, '__custom_name'):
142142
del self.__custom_name
143143

144-
145144
def __repr__(self):
146145
"""
147146
Default method for string representation.
@@ -191,11 +190,7 @@ cdef class SageObject:
191190
reprfunc = self._repr_
192191
except AttributeError:
193192
return super().__repr__()
194-
result = reprfunc()
195-
if isinstance(result, str):
196-
return result
197-
# Allow _repr_ to return unicode on Python 2
198-
return result.encode('utf-8')
193+
return reprfunc()
199194

200195
def _ascii_art_(self):
201196
r"""

0 commit comments

Comments
 (0)