Skip to content

Commit 3d9b089

Browse files
committed
Update docs for standard library imports
1 parent 4606bb2 commit 3d9b089

File tree

1 file changed

+63
-36
lines changed

1 file changed

+63
-36
lines changed

docs/standard_library_imports.rst

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,20 @@ modules from Python 3.3 (``future.backports``).
1010

1111
.. _list-standard-library-moves:
1212

13-
List of moved standard library modules
14-
--------------------------------------
13+
List of renamed standard library modules
14+
----------------------------------------
1515

16-
The complete list of modules available via one of the interfaces below is::
16+
As of version 0.14, the ``future`` package comes with top-level packages
17+
for Python 2.x that provide access to the reorganized standard library
18+
modules under their Python 3.x interfaces. The following renamed modules can be imported and used directly from Python 2/3 compatible code::
1719

18-
import builtins
20+
### Renamed modules:
1921

20-
from collections import Counter, OrderedDict # backported to Py2.6
21-
from collections import UserDict, UserList, UserString
22+
import builtins
2223

2324
import configparser
2425
import copyreg
2526

26-
import dbm
27-
import dbm.dumb
28-
import dbm.gnu
29-
import dbm.ndbm
30-
31-
from itertools import filterfalse, zip_longest
32-
3327
import html
3428
import html.entities
3529
import html.parser
@@ -42,21 +36,12 @@ The complete list of modules available via one of the interfaces below is::
4236

4337
import queue
4438

45-
import socketserver
46-
47-
from subprocess import check_output # backported to Py2.6
48-
from subprocess import getoutput, getstatusoutput
39+
import reprlib
4940

50-
from sys import intern
41+
import socketserver
5142

5243
from tkinter import ...
5344

54-
import urllib.error
55-
import urllib.parse
56-
import urllib.request
57-
import urllib.response
58-
import urllib.robotparser
59-
6045
import winreg # Windows only
6146

6247
import xmlrpc.client
@@ -66,19 +51,55 @@ The complete list of modules available via one of the interfaces below is::
6651
import _markupbase
6752
import _thread
6853

69-
.. Disabled: import test.support
7054

55+
List of refactored standard library modules
56+
-------------------------------------------
57+
58+
Some modules were refactored or extended from Python 2.6/2.7 to
59+
3.x but were neither renamed nor were the new interfaces backported. The
60+
``future`` package makes the Python 3.x interfaces available on Python
61+
2.x after running::
62+
63+
from future.standard_library import install_aliases
64+
install_aliases()
65+
66+
Then the following additional imports work in Python 2/3 compatible code::
7167

68+
from collections import Counter, OrderedDict # backported to Py2.6
69+
from collections import UserDict, UserList, UserString
70+
71+
import dbm
72+
import dbm.dumb
73+
import dbm.gnu
74+
import dbm.ndbm
75+
76+
from itertools import filterfalse, zip_longest
77+
78+
from subprocess import check_output # backported to Py2.6
79+
from subprocess import getoutput, getstatusoutput
80+
81+
from sys import intern
82+
83+
import test.support
7284

73-
Interfaces
74-
----------
85+
import urllib.error
86+
import urllib.parse
87+
import urllib.request
88+
import urllib.response
89+
import urllib.robotparser
7590

76-
There are currently four interfaces to the reorganized standard library.
7791

78-
Context-manager interface
79-
~~~~~~~~~~~~~~~~~~~~~~~~~
92+
Older interfaces
93+
----------------
8094

81-
The recommended interface is via a context-manager called ``hooks``::
95+
In addition to the above, ``future`` supports four other interfaces to
96+
the reorganized standard library, largely for historical reasons.
97+
98+
99+
Context-manager for import hooks
100+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101+
102+
The first interface is via a context-manager called ``hooks``::
82103

83104
from future.standard_library import hooks
84105
with hooks():
@@ -93,6 +114,9 @@ The recommended interface is via a context-manager called ``hooks``::
93114
import urllib.request
94115
# and other moved modules and definitions
95116

117+
This interface is straightforward and effective, using PEP 302 import
118+
hooks.
119+
96120
Direct interface
97121
~~~~~~~~~~~~~~~~
98122

@@ -180,7 +204,7 @@ modules on Py2::
180204
181205
182206
Comparing future.moves and six.moves
183-
------------------------------------
207+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
184208

185209
``future.moves`` and ``six.moves`` provide a similar Python 3-style
186210
interface to the native standard library module definitions.
@@ -224,11 +248,12 @@ are also available::
224248

225249
These are included in Python 2.7 and Python 3.x.
226250

251+
227252
Included backports
228253
------------------
229254

230-
Backports of the following modules from Python 3.3's standard library to Python 2.x are also
231-
available in ``future.backports``::
255+
Alpha-quality full backports of the following modules from Python 3.3's
256+
standard library to Python 2.x are also available in ``future.backports``::
232257

233258
http.client
234259
http.server
@@ -238,7 +263,9 @@ available in ``future.backports``::
238263
xmlrpc.client
239264
xmlrpc.server
240265
241-
These are currently of alpha quality. If you need the full backport of one of
242-
these, please open an issue `here
266+
Unlike the modules in the ``future.moves`` package or top-level namespace,
267+
these contain backports of new functionality introduced in Python 3.3.
268+
269+
If you need the full backport of one of these packages, please open an issue `here
243270
<https://github.com/PythonCharmers/python-future>`_.
244271

0 commit comments

Comments
 (0)