Skip to content

Commit 9eb2d11

Browse files
committed
Set past.utils as the canonical home for old_div()
1 parent 91aab45 commit 9eb2d11

File tree

6 files changed

+28
-23
lines changed

6 files changed

+28
-23
lines changed

docs/compatible_idioms.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ Integer division (rounding down):
188188
.. code:: python
189189
190190
# Python 2 and 3:
191-
from future.utils import old_div
191+
from past.utils import old_div
192192
193193
a = old_div(b, c) # always same as / on Py2
194194
Long integers

docs/notebooks/Writing Python 2-3 compatible code.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"metadata": {
33
"name": "",
4-
"signature": "sha256:f4ac8456d9c7976cb130d88556b7bbe2c3494a960d29e3eeffdca80a91b080e3"
4+
"signature": "sha256:c37888c8f9a1f8ba6d3693b55f121f2581ba744bc5feb6b9153a419891328945"
55
},
66
"nbformat": 3,
77
"nbformat_minor": 0,
@@ -491,7 +491,7 @@
491491
"collapsed": false,
492492
"input": [
493493
"# Python 2 and 3:\n",
494-
"from future.utils import old_div\n",
494+
"from past.utils import old_div\n",
495495
"\n",
496496
"a = old_div(b, c) # always same as / on Py2"
497497
],

future/tests/test_futurize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ def __truediv__(self, other):
11441144
"""
11451145
after = """
11461146
from __future__ import division
1147-
from past.utils import div
1147+
from past.utils import old_div
11481148
class Path(str):
11491149
def __div__(self, other):
11501150
return self.__truediv__(other)

future/utils/__init__.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
"""
22
A selection of cross-compatible functions for Python 2 and 3.
33
4-
These come from several sources:
5-
6-
* Jinja2 (BSD licensed: see
7-
https://github.com/mitsuhiko/jinja2/blob/master/LICENSE)
8-
* Pandas compatibility module pandas.compat
9-
* six.py by Benjamin Peterson
10-
* Django
11-
124
This exports useful functions for 2/3 compatible code that are not
135
builtins on Python 3:
146
@@ -68,6 +60,13 @@
6860
6961
On Python 3, this decorator is a no-op.
7062
63+
Some of the functions in this module come from the following sources:
64+
65+
* Jinja2 (BSD licensed: see
66+
https://github.com/mitsuhiko/jinja2/blob/master/LICENSE)
67+
* Pandas compatibility module pandas.compat
68+
* six.py by Benjamin Peterson
69+
* Django
7170
"""
7271

7372
import types
@@ -617,7 +616,7 @@ def exec_(code, globs=None, locs=None):
617616
exec("""exec code in globs, locs""")
618617

619618

620-
# Defined here too for backward compatibility:
619+
# Defined here for backward compatibility:
621620
def old_div(a, b):
622621
"""
623622
DEPRECATED: import ``old_div`` from ``past.utils`` instead.

past/__init__.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,6 @@
3333
>>> type(philosopher[0])
3434
<past.builtins.oldstr>
3535
36-
>>> # The div() function behaves like Python 2's / operator
37-
>>> # without "from __future__ import division"
38-
>>> from past.utils import div
39-
>>> div(3, 2) # like 3/2 in Py2
40-
0
41-
>>> div(3, 2.0) # like 3/2.0 in Py2
42-
1.5
43-
44-
This is an alias for ``future.utils.old_div``.
45-
4636
>>> # List-producing versions of range, reduce, map, filter
4737
>>> from past.builtins import range, reduce
4838
>>> range(10)

past/utils/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1+
"""
2+
Various non-built-in utility functions and definitions for Py2
3+
compatibility in Py3.
4+
5+
For example:
6+
7+
>>> # The old_div() function behaves like Python 2's / operator
8+
>>> # without "from __future__ import division"
9+
>>> from past.utils import old_div
10+
>>> old_div(3, 2) # like 3/2 in Py2
11+
0
12+
>>> old_div(3, 2.0) # like 3/2.0 in Py2
13+
1.5
14+
"""
15+
116
import sys
217
import numbers
318

419
PY3 = sys.version_info[0] == 3
520
PY2 = sys.version_info[0] == 2
621
PYPY = hasattr(sys, 'pypy_translation_info')
722

23+
824
def with_metaclass(meta, *bases):
925
"""
1026
Function from jinja2/_compat.py. License: BSD.

0 commit comments

Comments
 (0)