From 03f86d23f903615f9920dd238de7e5fd8d9b2206 Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Thu, 27 Oct 2016 22:34:35 +0200 Subject: [PATCH 1/9] Docs: update v0.16.x release date --- docs/whatsnew.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/whatsnew.rst b/docs/whatsnew.rst index 582b506b..cb86d005 100644 --- a/docs/whatsnew.rst +++ b/docs/whatsnew.rst @@ -5,7 +5,7 @@ What's New .. _whats-new-0.16.x: -What's new in version 0.16.0 (2016-09-22) +What's new in version 0.16.0 (2016-10-27) ========================================== This release removes the ``configparser`` package as an alias for From ba19436d4691fbfc409244538ff89c0c7abdfc84 Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Thu, 27 Oct 2016 22:45:26 +0200 Subject: [PATCH 2/9] Tweak What's New page for v0.16.0 --- docs/whatsnew.rst | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/whatsnew.rst b/docs/whatsnew.rst index cb86d005..ed606f17 100644 --- a/docs/whatsnew.rst +++ b/docs/whatsnew.rst @@ -9,10 +9,10 @@ What's new in version 0.16.0 (2016-10-27) ========================================== This release removes the ``configparser`` package as an alias for -``ConfigParser`` on Py2 to improve compatibility with the backported -`configparser package `. Previously -``python-future`` and the PyPI ``configparser`` backport clashed, causing -various compatibility issues. (Issues #118, #181) +``ConfigParser`` on Py2 to improve compatibility with Lukasz Langa's +backported `configparser `_ package. +Previously ``python-future`` and the ``configparser`` backport clashed, +causing various compatibility issues. (Issues #118, #181) If your code previously relied on ``configparser`` being supplied by ``python-future``, the recommended upgrade path is to run ``pip install @@ -26,15 +26,15 @@ effect on your system. This releases also fixes these bugs: - Fix ``newbytes`` constructor bug. (Issue #163) -- Fix semantics of `bool()` with `newobject`. (Issue #211) -- Fix `standard_library.install_aliases()` on PyPy. (Issue #205) -- Fix assertRaises for `pow` and `compile` on Python 3.5. (Issue #183) -- Fix return argument of `future.utils.ensure_new_type` if conversion to +- Fix semantics of ``bool()`` with ``newobject``. (Issue #211) +- Fix ``standard_library.install_aliases()`` on PyPy. (Issue #205) +- Fix assertRaises for ``pow`` and ``compile``` on Python 3.5. (Issue #183) +- Fix return argument of ``future.utils.ensure_new_type`` if conversion to new type does not exist. (Issue #185) -- Add missing `cmp_to_key` for Py2.6. (Issue #189) -- Allow the `old_div` fixer to be disabled. (Issue #190) +- Add missing ``cmp_to_key`` for Py2.6. (Issue #189) +- Allow the ``old_div`` fixer to be disabled. (Issue #190) - Improve compatibility with Google App Engine. (Issue #231) -- Add some missing imports to the `tkinter` and `tkinter.filedialog` +- Add some missing imports to the ``tkinter`` and ``tkinter.filedialog`` package namespaces. (Issues #212 and #233) - Fix ``raise_from`` on PY3 when the exception cannot be recreated from its repr. (Issues #213 and #235, fix provided by Varriount) From dd4f27ec99eec1ef9049f93db1176da0ea0d2e84 Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Thu, 27 Oct 2016 23:02:09 +0200 Subject: [PATCH 3/9] Update What's New doc to mention that issue #141 is fixed in v0.16.0 --- docs/whatsnew.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/whatsnew.rst b/docs/whatsnew.rst index ed606f17..f349ffef 100644 --- a/docs/whatsnew.rst +++ b/docs/whatsnew.rst @@ -36,8 +36,8 @@ This releases also fixes these bugs: - Improve compatibility with Google App Engine. (Issue #231) - Add some missing imports to the ``tkinter`` and ``tkinter.filedialog`` package namespaces. (Issues #212 and #233) -- Fix ``raise_from`` on PY3 when the exception cannot be recreated from - its repr. (Issues #213 and #235, fix provided by Varriount) +- More complete implementation of ``raise_from`` on PY3. (Issues #141, + #213 and #235, fix provided by Varriount) What's new in version 0.15.2 (2015-09-11) From a6bd30510feb5b988633647eed0015589caefcc1 Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Tue, 13 Dec 2016 15:29:47 +1100 Subject: [PATCH 4/9] Fix for install_aliases() omitting ChainMap (issue #226) --- docs/whatsnew.rst | 8 ++++++++ src/future/standard_library/__init__.py | 1 + 2 files changed, 9 insertions(+) diff --git a/docs/whatsnew.rst b/docs/whatsnew.rst index f349ffef..0e89646a 100644 --- a/docs/whatsnew.rst +++ b/docs/whatsnew.rst @@ -5,6 +5,14 @@ What's New .. _whats-new-0.16.x: +What's new in version 0.16.1 (unreleased) +========================================= + +This is a minor bug-fix release: + +- Fix `from collections import ChainMap` after install_aliases() (issue #226) + + What's new in version 0.16.0 (2016-10-27) ========================================== diff --git a/src/future/standard_library/__init__.py b/src/future/standard_library/__init__.py index aca58c3e..c2d35bdc 100644 --- a/src/future/standard_library/__init__.py +++ b/src/future/standard_library/__init__.py @@ -180,6 +180,7 @@ MOVES = [('collections', 'UserList', 'UserList', 'UserList'), ('collections', 'UserDict', 'UserDict', 'UserDict'), ('collections', 'UserString','UserString', 'UserString'), + ('collections', 'ChainMap', 'future.backports.misc', 'ChainMap'), ('itertools', 'filterfalse','itertools', 'ifilterfalse'), ('itertools', 'zip_longest','itertools', 'izip_longest'), ('sys', 'intern','__builtin__', 'intern'), From edc3f277c6cc074734401a57a2ac8952ba56c0ca Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Tue, 13 Dec 2016 15:41:44 +1100 Subject: [PATCH 5/9] Add tests for ChainMap (issue #226) --- tests/test_future/test_chainmap.py | 160 +++++++++++++++++++++ tests/test_future/test_standard_library.py | 7 + 2 files changed, 167 insertions(+) create mode 100644 tests/test_future/test_chainmap.py diff --git a/tests/test_future/test_chainmap.py b/tests/test_future/test_chainmap.py new file mode 100644 index 00000000..2440401b --- /dev/null +++ b/tests/test_future/test_chainmap.py @@ -0,0 +1,160 @@ +""" +Tests for the future.standard_library module +""" + +from __future__ import absolute_import, print_function +from future import standard_library +from future import utils +from future.tests.base import unittest, CodeHandler, expectedFailurePY2 + +import sys +import tempfile +import os +import copy +import textwrap +from subprocess import CalledProcessError + + +class TestChainMap(CodeHandler): + + def setUp(self): + self.interpreter = sys.executable + standard_library.install_aliases() + super(TestChainMap, self).setUp() + + def tearDown(self): + # standard_library.remove_hooks() + pass + + @staticmethod + def simple_cm(): + from collections import ChainMap + c = ChainMap() + c['one'] = 1 + c['two'] = 2 + + cc = c.new_child() + cc['one'] = 'one' + + return c, cc + + + def test_repr(self): + c, cc = TestChainMap.simple_cm() + + order1 = "ChainMap({'one': 'one'}, {'one': 1, 'two': 2})" + order2 = "ChainMap({'one': 'one'}, {'two': 2, 'one': 1})" + assert repr(cc) in [order1, order2] + + + def test_recursive_repr(self): + """ + Test for degnerative recursive cases. Very unlikely in + ChainMaps. But all must bow before the god of testing coverage. + """ + from collections import ChainMap + c = ChainMap() + c['one'] = c + assert repr(c) == "ChainMap({'one': ...})" + + + def test_get(self): + c, cc = TestChainMap.simple_cm() + + assert cc.get('two') == 2 + assert cc.get('three') == None + assert cc.get('three', 'notthree') == 'notthree' + + + def test_bool(self): + from collections import ChainMap + c = ChainMap() + assert not(bool(c)) + + c['one'] = 1 + c['two'] = 2 + assert bool(c) + + cc = c.new_child() + cc['one'] = 'one' + assert cc + + + def test_fromkeys(self): + from collections import ChainMap + keys = 'a b c'.split() + c = ChainMap.fromkeys(keys) + assert len(c) == 3 + assert c['a'] == None + assert c['b'] == None + assert c['c'] == None + + + def test_copy(self): + c, cc = TestChainMap.simple_cm() + new_cc = cc.copy() + assert new_cc is not cc + assert sorted(new_cc.items()) == sorted(cc.items()) + + + def test_parents(self): + c, cc = TestChainMap.simple_cm() + + new_c = cc.parents + assert c is not new_c + assert len(new_c) == 2 + assert new_c['one'] == c['one'] + assert new_c['two'] == c['two'] + + + def test_delitem(self): + c, cc = TestChainMap.simple_cm() + + with self.assertRaises(KeyError): + del cc['two'] + + del cc['one'] + assert len(cc) == 2 + assert cc['one'] == 1 + assert cc['two'] == 2 + + + def test_popitem(self): + c, cc = TestChainMap.simple_cm() + + assert cc.popitem() == ('one', 'one') + + with self.assertRaises(KeyError): + cc.popitem() + + + def test_pop(self): + c, cc = TestChainMap.simple_cm() + + assert cc.pop('one') == 'one' + + with self.assertRaises(KeyError): + cc.pop('two') + + assert len(cc) == 2 + + + def test_clear(self): + c, cc = TestChainMap.simple_cm() + + cc.clear() + assert len(cc) == 2 + assert cc['one'] == 1 + assert cc['two'] == 2 + + + def test_missing(self): + + c, cc = TestChainMap.simple_cm() + + with self.assertRaises(KeyError): + cc['clown'] + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_future/test_standard_library.py b/tests/test_future/test_standard_library.py index 647da550..7da6b75b 100644 --- a/tests/test_future/test_standard_library.py +++ b/tests/test_future/test_standard_library.py @@ -247,6 +247,13 @@ def test_itertools_zip_longest(self): self.assertEqual(list(zip_longest(a, b)), [(1, 2), (2, 4), (None, 6)]) + def test_ChainMap(self): + """ + Tests whether collections.ChainMap is available. + """ + from collections import ChainMap + cm = ChainMap() + @unittest.expectedFailure @unittest.skipIf(utils.PY3, 'generic import tests are for Py2 only') def test_import_failure_from_module(self): From b4666394e7cc574f7396f4ff70b7a6ee226ef6ad Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Tue, 13 Dec 2016 15:02:04 +1100 Subject: [PATCH 6/9] Add Py3.5 to Travis-CI tests --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 6e20573f..da167c1a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: python python: + - "3.5" - "3.4" - "3.3" - "2.7" From 9fcde90f29b6e278417dac243170ebb79ce65283 Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Fri, 18 May 2018 09:45:41 +1000 Subject: [PATCH 7/9] Fix small doc bug: location of itervalues --- docs/compatible_idioms.rst | 2 +- docs/notebooks/Writing Python 2-3 compatible code.ipynb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/compatible_idioms.rst b/docs/compatible_idioms.rst index e48ac6d1..37a7135f 100644 --- a/docs/compatible_idioms.rst +++ b/docs/compatible_idioms.rst @@ -512,7 +512,7 @@ Iterable dict values: .. code:: python # Python 2 and 3: option 2 - from builtins import itervalues + from future.utils import itervalues # or from six import itervalues diff --git a/docs/notebooks/Writing Python 2-3 compatible code.ipynb b/docs/notebooks/Writing Python 2-3 compatible code.ipynb index f33a9204..8ac0bd80 100644 --- a/docs/notebooks/Writing Python 2-3 compatible code.ipynb +++ b/docs/notebooks/Writing Python 2-3 compatible code.ipynb @@ -1129,7 +1129,7 @@ "outputs": [], "source": [ "# Python 2 and 3: option 2\n", - "from builtins import itervalues\n", + "from future.utils import itervalues\n", "# or\n", "from six import itervalues\n", "\n", From 7cf0f9db449297a99211133651544ee412a2d805 Mon Sep 17 00:00:00 2001 From: Johann-Michael Thiebaut Date: Thu, 5 Jul 2018 09:43:46 +0200 Subject: [PATCH 8/9] os.makedirs can fail --- src/past/translation/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/past/translation/__init__.py b/src/past/translation/__init__.py index 7b21d9f5..6ea94536 100644 --- a/src/past/translation/__init__.py +++ b/src/past/translation/__init__.py @@ -402,9 +402,9 @@ def load_module(self, fullname): code = compile(source, self.pathname, 'exec') dirname = os.path.dirname(cachename) - if not os.path.exists(dirname): - os.makedirs(dirname) try: + if not os.path.exists(dirname): + os.makedirs(dirname) with open(cachename, 'wb') as f: data = marshal.dumps(code) f.write(data) From 923d473162974657f4c6a0912c40d3c33c30a0a5 Mon Sep 17 00:00:00 2001 From: "Jordan M. Adler" Date: Mon, 10 Sep 2018 11:45:55 -0700 Subject: [PATCH 9/9] Revert "Fix `past.translation` on read-only file systems" --- src/past/translation/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/past/translation/__init__.py b/src/past/translation/__init__.py index 6ea94536..7b21d9f5 100644 --- a/src/past/translation/__init__.py +++ b/src/past/translation/__init__.py @@ -402,9 +402,9 @@ def load_module(self, fullname): code = compile(source, self.pathname, 'exec') dirname = os.path.dirname(cachename) + if not os.path.exists(dirname): + os.makedirs(dirname) try: - if not os.path.exists(dirname): - os.makedirs(dirname) with open(cachename, 'wb') as f: data = marshal.dumps(code) f.write(data)