Skip to content

Commit 004dcab

Browse files
committed
Doc tweaks
1 parent 5b43315 commit 004dcab

4 files changed

Lines changed: 21 additions & 21 deletions

File tree

‎docs/int_object.rst‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ Python 2::
2020

2121
``future`` includes a backport of Python 3's ``int`` that
2222
is a subclass of Python 2's ``long`` with the same representation
23-
behaviour as Python 3's ``int``. To ensure an integer is long compatibly both
24-
Py3 and Py2, cast it like this::
23+
behaviour as Python 3's ``int``. To ensure an integer is long compatibly with
24+
both Py3 and Py2, cast it like this::
2525

26-
>>> from future.builtins import *
26+
>>> from future.builtins import int
2727
>>> must_be_a_long_integer = int(1234)
2828

2929
The backported ``int`` object helps with writing doctests and simplifies code

‎docs/isinstance.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ After importing the builtins from ``future``, all these tests pass on
4040
Python 2 as on Python 3::
4141

4242
>>> from __future__ import unicode_literals
43-
>>> from future.builtins import *
43+
>>> from future.builtins import bytes, int, str
4444

4545
>>> assert isinstance(10, int)
4646
>>> assert isinstance(10**100, int)

‎docs/open_function.rst‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ contents as (unicode) strings unless the binary (``b``) flag is passed, as in::
88
99
open(filename, 'rb')
1010

11-
in which case it returns a Py3 :class:`bytes` object.
12-
13-
``future.builtins`` provides a compatible ``open`` function on Py2,
14-
which uses the ``open`` backport available in the standard library :mod:`io`
15-
module on Py2.6+.
16-
17-
When porting code from Python 2, be aware of the different return types from
18-
methods such as :func:`read()` from the file object that ``open`` returns.
19-
20-
Note that the output of :func:`read()` etc. is not automatically cast to the
21-
appropriate ``future.builtins.bytes`` or ``future.builtins.str`` type. If you
22-
need the stricter type-checking of Py3 on Py2 as well, you can cast it
23-
explicitly as follows::
11+
in which case its methods like :func:`read` return Py3 :class:`bytes` objects.
12+
13+
``future.builtins`` provides an ``open`` function on Py2 that is mostly
14+
compatible with that on Python 3 (e.g. it offers keyword arguments like
15+
``encoding``). This maps to the ``open`` backport available in the standard
16+
library :mod:`io` module on Py2.6 and Py2.7.
17+
18+
One difference to be aware of between the Python 3 ``open`` and
19+
``future.builtins.open`` on Python 2 is that the return types of methods such
20+
as :func:`read()` from the file object that ``open`` returns are not
21+
automatically cast to the appropriate ``future.builtins.bytes`` or
22+
``future.builtins.str`` types. If you need the returned data to behave the same
23+
way on Py2 as on Py3, you can cast it explicitly as follows::
2424

2525
from __future__ import unicode_literals
2626
from future.builtins import *

‎docs/str_object.rst‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ Then, for example, the following code has the same effect on Py2 as on Py3::
4444
TypeError: argument can't be <type 'str'>
4545

4646
Various other operations that mix strings and bytes or other types are
47-
permitted on Py2 with the :class:`newstr`` class even though they are
48-
illegal with Python 3. For example::
47+
permitted on Py2 with the :class:`future.builtins.str` class even though they
48+
are illegal with Python 3. For example::
4949

5050
>>> s2 = b'/' + str('ABCD')
5151
>>> s2
@@ -71,8 +71,8 @@ they are unicode. (See ``posixpath.py``.) Another example is the
7171
..
7272
.. On Py3, these raise TypeErrors.
7373
74-
In most other ways, these :class:`str` objects on Py2 have the same
75-
behaviours as Python 3's :class:`str`::
74+
In most other ways, these :class:`future.builtins.str` objects on Py2 have the
75+
same behaviours as Python 3's :class:`str`::
7676

7777
>>> s = str('ABCD')
7878
>>> assert repr(s) == 'ABCD' # consistent repr with Py3 (no u prefix)

0 commit comments

Comments
 (0)