Skip to content

Commit 8075250

Browse files
committed
Merge branch 'maint-v0.10.x'
Conflicts: docs/_templates/layout.html docs/conf.py docs/dict_object.rst docs/imports.rst docs/open_function.rst docs/overview.rst future/__init__.py future/standard_library/__init__.py future/tests/test_standard_library.py
2 parents 88ed26f + c5fc7c3 commit 8075250

29 files changed

Lines changed: 390 additions & 227 deletions

README.rst

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Features
2020
- provides backports and remappings for 15 builtins with different
2121
semantics on Py3 versus Py2
2222
- provides backports and remappings from the Py3 standard library
23-
- 300+ unit tests
23+
- 330+ unit tests
2424
- ``futurize`` script based on ``2to3``, ``3to2`` and parts of
2525
``python-modernize`` for automatic conversion from either Py2 or Py3 to a
2626
clean single-source codebase compatible with Python 2.6+ and Python 3.3+.
@@ -33,24 +33,12 @@ Code examples
3333
-------------
3434

3535
``future`` is designed to be imported at the top of each Python module
36-
together with Python's built-in ``__future__`` module like this::
37-
38-
from __future__ import (absolute_import, division,
39-
print_function, unicode_literals)
40-
from future import standard_library
41-
from future.builtins import *
36+
together with Python's built-in ``__future__`` module. For example, this
37+
code behaves the same way on Python 2.6/2.7 after these imports as it does
38+
on Python 3::
4239
43-
followed by standard Python 3 code. The imports have no effect on Python
44-
3 but allow the code to run mostly unchanged on Python 3 and Python 2.6/2.7.
45-
46-
For example, this code behaves the same way on Python 2.6/2.7 after these
47-
imports as it normally does on Python 3::
48-
49-
# Support for renamed standard library modules via import hooks
50-
from http.client import HttpConnection
51-
from itertools import filterfalse
52-
import html.parser
53-
import queue
40+
from __future__ import absolute_import, division, print_function
41+
from future import bytes, str, open, super, zip, round, input, int
5442

5543
# Backported Py3 bytes object
5644
b = bytes(b'ABCD')
@@ -98,8 +86,21 @@ imports as it normally does on Python 3::
9886
# Compatible output from isinstance() across Py2/3:
9987
assert isinstance(2**64, int) # long integers
10088
assert isinstance(u'blah', str)
101-
assert isinstance('blah', str) # with unicode_literals in effect
102-
assert isinstance(b'bytestring', bytes)
89+
assert isinstance('blah', str) # if unicode_literals is in effect
90+
91+
There is also support for renamed standard library modules in the form of import hooks::
92+
93+
from future import standard_library
94+
standard_library.install_hooks()
95+
96+
from http.client import HttpConnection
97+
from itertools import filterfalse
98+
import html.parser
99+
import queue
100+
101+
To disable these at the end of a module, use::
102+
103+
standard_library.remove_hooks()
103104

104105

105106
Documentation
@@ -114,16 +115,7 @@ Credits
114115
:Author: Ed Schofield
115116
:Sponsor: Python Charmers Pty Ltd, Australia, and Python Charmers Pte
116117
Ltd, Singapore. http://pythoncharmers.com
117-
:Others: - The backported ``super()`` and ``range()`` functions are
118-
derived from Ryan Kelly's ``magicsuper`` module and Dan
119-
Crosta's ``xrange`` module.
120-
- The ``futurize`` script uses ``lib2to3``, ``lib3to2``, and
121-
parts of Armin Ronacher's ``python-modernize`` code.
122-
- The ``python_2_unicode_compatible`` decorator is from
123-
Django. The ``implements_iterator`` and ``with_metaclass``
124-
decorators are from Jinja2.
125-
- Documentation is generated using ``sphinx`` using
126-
``sphinx_bootstrap_theme``.
118+
:Others: See http://python-future.org/credits.html
127119

128120

129121
Licensing

docs/_templates/layout.html

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
{# Import the theme's layout. #}
22
{% extends "!layout.html" %}
33

4-
{# Add some extra stuff before and use existing with 'super()' call. #}
5-
{% block footer %}
4+
{% block extrahead %}
65
{{ super() }}
7-
<script>
8-
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
9-
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
10-
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
11-
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
12-
13-
ga('create', 'UA-19344199-2', 'python-future.org');
14-
ga('send', 'pageview');
15-
6+
<script type="text/javascript">
7+
var _gaq = _gaq || [];
8+
_gaq.push(['_setAccount', 'UA-19344199-2']);
9+
_gaq.push(['_trackPageview']);
1610
</script>
11+
{% endblock %}
1712

18-
13+
{% block footer %}
14+
{{ super() }}
15+
<div class="footer">
16+
<script type="text/javascript">
17+
(function() {
18+
var ga = document.createElement('script');
19+
ga.src = ('https:' == document.location.protocol ?
20+
'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
21+
ga.setAttribute('async', 'true');
22+
document.documentElement.firstChild.appendChild(ga);
23+
})();
24+
</script>
25+
</div>
1926
{% endblock %}
2027

2128

docs/automatic_conversion.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,18 @@ Run with::
195195

196196
futurize —-stage2 myfolder/*.py
197197

198-
This adds three further imports::
198+
This adds these further imports to each module::
199199

200200
from __future__ import unicode_literals
201201
from future import standard_library
202-
from future.builtins import *
202+
from future.builtins import open
203+
from future.builtins import str # etc. for the builtins used in the module
203204

204-
to each module and makes other changes needed to support Python 3, such as
205+
and makes other changes needed to support Python 3, such as
205206
renaming standard-library imports to their Py3 names.
206207

207-
All strings are then unicode (on Py2 as on Py3) unless explicitly marked with a ``b''`` prefix.
208+
All strings are then implicitly unicode (on Py2 as on Py3) unless they were previously
209+
explicitly marked with a ``b''`` prefix.
208210

209211
Ideally the output of this stage should not be a ``SyntaxError`` on either
210212
Python 3 or Python 2.

docs/bytes_object.rst

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,14 @@ strict separation of unicode strings and byte strings as Python 3's
3333
File "<stdin>", line 1, in <module>
3434
TypeError: sequence item 0: expected bytes, found unicode string
3535

36-
Various other comparisons between byte-strings and other types return a result
37-
in Py2 but raise a TypeError in Py3. For example, this is permissible on
38-
Py2::
36+
>>> b == u'ABCD'
37+
False
3938

40-
>>> b'u' > 10
41-
True
42-
43-
>>> b'u' <= u'u'
44-
True
39+
>>> b < u'abc'
40+
Traceback (most recent call last):
41+
File "<stdin>", line 1, in <module>
42+
TypeError: unorderable types: bytes() and <type 'unicode'>
4543

46-
On Py3, these raise TypeErrors.
4744

4845
In most other ways, these :class:`bytes` objects have identical
4946
behaviours to Python 3's :class:`bytes`::
@@ -57,7 +54,7 @@ Currently the easiest way to ensure identical behaviour of byte-strings
5754
in a Py2/3 codebase is to wrap all byte-string literals ``b'...'`` in a
5855
:func:`~bytes` call as follows::
5956
60-
from future.builtins import *
57+
from future.builtins import bytes
6158
6259
# ...
6360

docs/changelog.rst

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,55 @@ over large dictionaries. For example::
9595

9696
For more information, see :ref:`dict-object`.
9797

98+
99+
Refactoring of standard_library hooks (v0.10.2)
100+
-----------------------------------------------
101+
102+
There is a new context manager ``future.standard_library.hooks``. Use it like
103+
this::
104+
105+
from future import standard_library
106+
with standard_library.hooks():
107+
import queue
108+
import configserver
109+
# etc.
110+
111+
If not using this decorator, it is now encouraged to add an explicit call to
112+
``standard_library.install_hooks()`` as follows::
113+
114+
from future import standard_library
115+
standard_library.install_hooks()
116+
117+
import queue
118+
import html
119+
import http.client
120+
# etc.
121+
122+
and to remove the hooks afterwards with::
123+
124+
standard_library.remove_hooks()
125+
126+
The functions ``install_hooks()`` and ``remove_hooks()`` were previously
127+
called ``enable_hooks()`` and ``disable_hooks()``. The old names are
128+
still available as aliases.
129+
130+
131+
Utility functions raise_ and exec_
132+
----------------------------------
133+
134+
The functions ``raise_with_traceback()`` and ``raise_()`` were
135+
added to ``future.utils`` to offer either the Python 3.x or Python 2.x
136+
behaviour for raising exceptions. Thanks to Joel Tratner for the
137+
contribution of these. ``future.utils.reraise()`` is now deprecated.
138+
139+
A portable ``exec_()`` function has been added to ``future.utils`` from
140+
``six``.
141+
142+
98143
Bugfixes
99144
--------
100145
- Fixed newint.__divmod__
101-
- Improved robustness of :func:`disable_hooks` and :func:`enable_hooks()` in :mod:`future.standard_library`
146+
- Improved robustness of installing and removing import hooks in :mod:`future.standard_library`
102147
- v0.10.1: Fixed broken ``pip install future`` on Py3
103148

104149

docs/conf.py

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,68 @@
100100
# Theme options are theme-specific and customize the look and feel of a theme
101101
# further. For a list of options available for each theme, see the
102102
# documentation.
103-
#html_theme_options = {}
103+
html_theme_options = {
104+
# Navigation bar title. (Default: ``project`` value)
105+
'navbar_title': "Python-Future",
106+
107+
# Tab name for entire site. (Default: "Site")
108+
'navbar_site_name': "All pages",
109+
110+
# A list of tuples containing pages or urls to link to.
111+
# Valid tuples should be in the following forms:
112+
# (name, page) # a link to a page
113+
# (name, "/aa/bb", 1) # a link to an arbitrary relative url
114+
# (name, "http://example.com", True) # arbitrary absolute url
115+
# Note the "1" or "True" value above as the third argument to indicate
116+
# an arbitrary url.
117+
'navbar_links': [
118+
("Overview", "overview.html"),
119+
("FAQ", "faq.html", True),
120+
# ("Link", "http://example.com", True),
121+
],
122+
123+
# Render the next and previous page links in navbar. (Default: true)
124+
'navbar_sidebarrel': True,
125+
126+
# Render the current pages TOC in the navbar. (Default: true)
127+
'navbar_pagenav': True,
128+
129+
# Global TOC depth for "site" navbar tab. (Default: 1)
130+
# Switching to -1 shows all levels.
131+
'globaltoc_depth': 2,
132+
133+
# Include hidden TOCs in Site navbar?
134+
#
135+
# Note: If this is "false", you cannot have mixed ``:hidden:`` and
136+
# non-hidden ``toctree`` directives in the same page, or else the build
137+
# will break.
138+
#
139+
# Values: "true" (default) or "false"
140+
'globaltoc_includehidden': "true",
141+
142+
# HTML navbar class (Default: "navbar") to attach to <div> element.
143+
# For black navbar, do "navbar navbar-inverse"
144+
'navbar_class': "navbar navbar-inverse",
145+
146+
# Fix navigation bar to top of page?
147+
# Values: "true" (default) or "false"
148+
'navbar_fixed_top': "true",
149+
150+
# Location of link to source.
151+
# Options are "nav" (default), "footer" or anything else to exclude.
152+
'source_link_position': "none",
153+
154+
# Bootswatch (http://bootswatch.com/) theme.
155+
#
156+
# Options are nothing with "" (default) or the name of a valid theme
157+
# such as "amelia" or "cosmo" or "united".
158+
'bootswatch_theme': "cerulean",
159+
160+
# Choose Bootstrap version.
161+
# Values: "3" (default) or "2" (in quotes)
162+
'bootstrap_version': "3",
163+
}
164+
104165

105166
# Add any paths that contain custom themes here, relative to this directory.
106167
#html_theme_path = []

docs/credits.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ Credits
1212
- The ``python_2_unicode_compatible`` decorator is from
1313
Django. The ``implements_iterator`` and ``with_metaclass``
1414
decorators are from Jinja2.
15-
- ``future`` incorporates the ``six`` module by Benjamin
16-
Peterson as ``future.utils.six``.
17-
- Documentation is generated using ``sphinx`` using an
18-
adaptation of Armin Ronacher's stylesheets from Jinja2.
15+
- The ``exec_`` function and some others in ``future.utils``
16+
are from the ``six`` module by Benjamin Peterson.
17+
- The ``raise_`` and ``raise_with_traceback`` functions were
18+
contributed by Jeff Tratner.
19+
- Documentation is generated with ``sphinx`` using the
20+
``sphinx-bootstrap`` theme.
1921

2022
.. _licence:
2123

docs/custom_str_methods.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Py2 and define ``__str__`` to encode it as utf-8::
1818
return u'Unicode string: \u5b54\u5b50'
1919
a = MyClass()
2020

21-
# This then prints the Chinese characters for Confucius:
21+
# This then prints the name of a Chinese philosopher:
2222
print(a)
2323

2424
This decorator is identical to the decorator of the same name in

0 commit comments

Comments
 (0)