From 31bb060cf15425eee88a43b1239c90c0d023186f Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Thu, 11 Sep 2014 23:03:54 +0100 Subject: Add python_2_unicode_comaptible from Django --- six.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/six.py b/six.py index 21b0e80..35530a3 100644 --- a/six.py +++ b/six.py @@ -737,6 +737,25 @@ def add_metaclass(metaclass): return metaclass(cls.__name__, cls.__bases__, orig_vars) return wrapper + +def python_2_unicode_compatible(klass): + """ + A decorator that defines __unicode__ and __str__ methods under Python 2. + Under Python 3 it does nothing. + + To support Python 2 and 3 with a single code base, define a __str__ method + returning text and apply this decorator to the class. + """ + if six.PY2: + if '__str__' not in klass.__dict__: + raise ValueError("@python_2_unicode_compatible cannot be applied " + "to %s because it doesn't define __str__()." % + klass.__name__) + klass.__unicode__ = klass.__str__ + klass.__str__ = lambda self: self.__unicode__().encode('utf-8') + return klass + + # Complete the moves implementation. # This code is at the end of this module to speed up module loading. # Turn this module into a package. -- cgit v1.2.1 From 318a802db349df01dde2071942034c979d899c5e Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Tue, 16 Sep 2014 10:32:06 +0100 Subject: add tests for python_2_unicode_comapatible --- six.py | 2 +- test_six.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/six.py b/six.py index 35530a3..e7667af 100644 --- a/six.py +++ b/six.py @@ -746,7 +746,7 @@ def python_2_unicode_compatible(klass): To support Python 2 and 3 with a single code base, define a __str__ method returning text and apply this decorator to the class. """ - if six.PY2: + if PY2: if '__str__' not in klass.__dict__: raise ValueError("@python_2_unicode_compatible cannot be applied " "to %s because it doesn't define __str__()." % diff --git a/test_six.py b/test_six.py index 0125d6b..c744b29 100644 --- a/test_six.py +++ b/test_six.py @@ -734,3 +734,24 @@ def test_add_metaclass(): __slots__ = "__weakref__", MySlotsWeakref = six.add_metaclass(Meta)(MySlotsWeakref) assert type(MySlotsWeakref) is Meta + + +def test_python_2_unicode_compatible(): + @six.python_2_unicode_compatible + class MyTest(object): + def __str__(self): + return six.u('hello') + + def __bytes__(self): + return six.b('hello') + + my_test = MyTest() + + if six.PY2: + assert str(my_test) == six.b("hello") + assert unicode(my_test) == six.u("hello") + elif six.PY3: + assert bytes(my_test) == six.b("hello") + assert str(my_test) == six.u("hello") + + assert getattr(six.moves.builtins, 'bytes', str)(my_test) == six.b("hello") -- cgit v1.2.1 From 20d7a1588e851eb8fc35ba481d7018b841ed9953 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Tue, 25 Nov 2014 18:22:19 -0500 Subject: Added unittest aliases. --- documentation/index.rst | 33 +++++++++++++++++++++++++++++++++ six.py | 18 ++++++++++++++++++ test_six.py | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) diff --git a/documentation/index.rst b/documentation/index.rst index 7851421..6b3ad1e 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -746,6 +746,39 @@ Contains classes from Python 3's :mod:`py3:urllib.response` and Python 2's: * :class:`py2:urllib.addinfourl` +unittest assertions +<<<<<<<<<<<<<<<<<<< + +.. currentmodule:: six + +Contains compatibility shims for unittest assertions that have been renamed. +The parameters are the same as their aliases, but you must pass the test method +as the first argument. For example:: + + import six + import unittest + + class TestAssertCountEqual(unittest.TestCase): + def test(self): + six.assertCountEqual(self, (1, 2), [2, 1]) + + +.. function:: assertCountEqual() + + Alias for :meth:`~py3:unittest.TestCase.assertCountEqual` on Python 3 and + :meth:`~py2:unittest.TestCase.assertItemsEqual` on Python 2. + +.. function:: assertRaisesRegex() + + Alias for :meth:`~py3:unittest.TestCase.assertRaisesRegex` on Python 3 and + :meth:`~py2:unittest.TestCase.assertRaisesRegexp` on Python 2. + +.. function:: assertRegex() + + Alias for :meth:`~py3:unittest.TestCase.assertRegex` on Python 3 and + :meth:`~py2:unittest.TestCase.assertRegexpMatches` on Python 2. + + Advanced - Customizing renames <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< diff --git a/six.py b/six.py index a8cdb22..303fd2d 100644 --- a/six.py +++ b/six.py @@ -610,6 +610,9 @@ if PY3: import io StringIO = io.StringIO BytesIO = io.BytesIO + _assertCountEqual = "assertCountEqual" + _assertRaisesRegex = "assertRaisesRegex" + _assertRegex = "assertRegex" else: def b(s): return s @@ -625,10 +628,25 @@ else: iterbytes = functools.partial(itertools.imap, ord) import StringIO StringIO = BytesIO = StringIO.StringIO + _assertCountEqual = "assertItemsEqual" + _assertRaisesRegex = "assertRaisesRegexp" + _assertRegex = "assertRegexpMatches" _add_doc(b, """Byte literal""") _add_doc(u, """Text literal""") +def assertCountEqual(self, *args, **kwargs): + return getattr(self, _assertCountEqual)(*args, **kwargs) + + +def assertRaisesRegex(self, *args, **kwargs): + return getattr(self, _assertRaisesRegex)(*args, **kwargs) + + +def assertRegex(self, *args, **kwargs): + return getattr(self, _assertRegex)(*args, **kwargs) + + if PY3: exec_ = getattr(moves.builtins, "exec") diff --git a/test_six.py b/test_six.py index b0ccd8d..c023862 100644 --- a/test_six.py +++ b/test_six.py @@ -1,6 +1,7 @@ import operator import sys import types +import unittest import py @@ -773,3 +774,39 @@ def test_add_metaclass(): __slots__ = "__weakref__", MySlotsWeakref = six.add_metaclass(Meta)(MySlotsWeakref) assert type(MySlotsWeakref) is Meta + + +@py.test.mark.skipif("sys.version_info[:2] < (2, 7)") +def test_assertCountEqual(): + class TestAssertCountEqual(unittest.TestCase): + def test(self): + with self.assertRaises(AssertionError): + six.assertCountEqual(self, (1, 2), [3, 4, 5]) + + six.assertCountEqual(self, (1, 2), [2, 1]) + + TestAssertCountEqual('test').test() + + +def test_assertRegex(): + class TestAssertRegex(unittest.TestCase): + def test(self): + with self.assertRaises(AssertionError): + six.assertRegex(self, 'test', r'^a') + + six.assertRegex(self, 'test', r'^t') + + TestAssertRegex('test').test() + + +def test_assertRaisesRegex(): + class TestAssertRaisesRegex(unittest.TestCase): + def test(self): + with six.assertRaisesRegex(self, AssertionError, '^Foo'): + raise AssertionError('Foo') + + with self.assertRaises(AssertionError): + with six.assertRaisesRegex(self, AssertionError, r'^Foo'): + raise AssertionError('Bar') + + TestAssertRaisesRegex('test').test() -- cgit v1.2.1 From 9f4c34a72ee52326b17cab92cd008399b920a5f6 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 5 Dec 2014 20:12:27 -0800 Subject: Ensure wraps passes along the assigned + updated params Fixes issue #105 --- six.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/six.py b/six.py index a8cdb22..11843f8 100644 --- a/six.py +++ b/six.py @@ -729,7 +729,9 @@ if sys.version_info[0:2] < (3, 4): def wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS, updated=functools.WRAPPER_UPDATES): def wrapper(f): - f = functools.wraps(wrapped)(f) + f = functools.wraps(wrapped, + assigned=assigned, + updated=updated)(f) f.__wrapped__ = wrapped return f return wrapper -- cgit v1.2.1 From d00e00a327483379c13dc8789413d4ef31392259 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 9 Dec 2014 10:42:11 -0500 Subject: http -> https --- README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index 4de73fa..32bab7c 100644 --- a/README +++ b/README @@ -9,8 +9,8 @@ notice must be retained.) Online documentation is at http://pythonhosted.org/six/. -Bugs can be reported to http://bitbucket.org/gutworth/six. The code can also be -found there. +Bugs can be reported to https://bitbucket.org/gutworth/six. The code can also +be found there. For questions about six or porting in general, email the python-porting mailing list: http://mail.python.org/mailman/listinfo/python-porting -- cgit v1.2.1 From 2a0da34c131bbe1c8633875956b4cb28187b4f66 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 9 Dec 2014 10:59:11 -0500 Subject: use positional arguments in call --- six.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/six.py b/six.py index 11843f8..686c20a 100644 --- a/six.py +++ b/six.py @@ -729,9 +729,7 @@ if sys.version_info[0:2] < (3, 4): def wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS, updated=functools.WRAPPER_UPDATES): def wrapper(f): - f = functools.wraps(wrapped, - assigned=assigned, - updated=updated)(f) + f = functools.wraps(wrapped, assigned, updated)(f) f.__wrapped__ = wrapped return f return wrapper -- cgit v1.2.1 From cc5097e82156c35c21ab2ecfbad1d326bf9c5459 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 9 Dec 2014 10:59:50 -0500 Subject: add test for issue #105 --- test_six.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test_six.py b/test_six.py index b0ccd8d..d5555e8 100644 --- a/test_six.py +++ b/test_six.py @@ -701,6 +701,18 @@ def test_wraps(): assert k is original_k assert not hasattr(k, '__wrapped__') + def f(g, assign, update): + def w(): + return 42 + w.glue = {"foo" : "bar"} + return six.wraps(g, assign, update)(w) + k.glue = {"melon" : "egg"} + k.turnip = 43 + k = f(k, ["turnip"], ["glue"]) + assert k.__name__ == "w" + assert k.turnip == 43 + assert k.glue == {"melon" : "egg", "foo" : "bar"} + def test_add_metaclass(): class Meta(type): -- cgit v1.2.1 From ec8807c7c3764dc20432898b9732003f60eeb94c Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 9 Dec 2014 11:01:02 -0500 Subject: add NEWS note for #105 --- CHANGES | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES b/CHANGES index cae8ef0..25930bd 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,9 @@ This file lists the changes in each six version. Development version ------------------- +- Issue #105 and pull request #58: Ensure `six.wraps` respects the *updated* and + *assigned* arguments. + - Issue #102: Add `raise_from` to abstract out Python 3's raise from syntax. - Issue #97: Optimize `six.iterbytes` on Python 2. -- cgit v1.2.1 From 7736215b48c3687e30784b48ee71bf51efe01b17 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 16 Dec 2014 19:40:49 -0500 Subject: color commentary --- documentation/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/index.rst b/documentation/index.rst index 7851421..f3ee0cc 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -18,7 +18,7 @@ tracker and code hosting is on `BitBucket `_. The name, "six", comes from the fact that 2*3 equals 6. Why not addition? Multiplication is more powerful, and, anyway, "five" has already been snatched -away by the Zope Five project. +away by the (admittedly now moribund) Zope Five project. Indices and tables -- cgit v1.2.1 From aeff5437821ca4b2a8aea2ccf0ef9adcd0bae302 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 2 Jan 2015 09:27:50 -0600 Subject: update changelog --- CHANGES | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES b/CHANGES index 25930bd..e12508a 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,9 @@ This file lists the changes in each six version. Development version ------------------- +- Pull request #57 and issue #50: Add several compatibility methods for unittest + assertions that were renamed between Python 2 and 3. + - Issue #105 and pull request #58: Ensure `six.wraps` respects the *updated* and *assigned* arguments. -- cgit v1.2.1 From 532be7ae72888e7e8c5779d330a8abaa1d94254e Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 2 Jan 2015 09:29:09 -0600 Subject: move unittest assertions section up --- documentation/index.rst | 66 ++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/documentation/index.rst b/documentation/index.rst index 25e5345..806504e 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -437,6 +437,39 @@ string data in all Python versions. :class:`py3:io.BytesIO`. +unittest assertions +>>>>>>>>>>>>>>>>>>> + +.. currentmodule:: six + +Contains compatibility shims for unittest assertions that have been renamed. +The parameters are the same as their aliases, but you must pass the test method +as the first argument. For example:: + + import six + import unittest + + class TestAssertCountEqual(unittest.TestCase): + def test(self): + six.assertCountEqual(self, (1, 2), [2, 1]) + + +.. function:: assertCountEqual() + + Alias for :meth:`~py3:unittest.TestCase.assertCountEqual` on Python 3 and + :meth:`~py2:unittest.TestCase.assertItemsEqual` on Python 2. + +.. function:: assertRaisesRegex() + + Alias for :meth:`~py3:unittest.TestCase.assertRaisesRegex` on Python 3 and + :meth:`~py2:unittest.TestCase.assertRaisesRegexp` on Python 2. + +.. function:: assertRegex() + + Alias for :meth:`~py3:unittest.TestCase.assertRegex` on Python 3 and + :meth:`~py2:unittest.TestCase.assertRegexpMatches` on Python 2. + + Renamed modules and attributes compatibility >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> @@ -746,39 +779,6 @@ Contains classes from Python 3's :mod:`py3:urllib.response` and Python 2's: * :class:`py2:urllib.addinfourl` -unittest assertions -<<<<<<<<<<<<<<<<<<< - -.. currentmodule:: six - -Contains compatibility shims for unittest assertions that have been renamed. -The parameters are the same as their aliases, but you must pass the test method -as the first argument. For example:: - - import six - import unittest - - class TestAssertCountEqual(unittest.TestCase): - def test(self): - six.assertCountEqual(self, (1, 2), [2, 1]) - - -.. function:: assertCountEqual() - - Alias for :meth:`~py3:unittest.TestCase.assertCountEqual` on Python 3 and - :meth:`~py2:unittest.TestCase.assertItemsEqual` on Python 2. - -.. function:: assertRaisesRegex() - - Alias for :meth:`~py3:unittest.TestCase.assertRaisesRegex` on Python 3 and - :meth:`~py2:unittest.TestCase.assertRaisesRegexp` on Python 2. - -.. function:: assertRegex() - - Alias for :meth:`~py3:unittest.TestCase.assertRegex` on Python 3 and - :meth:`~py2:unittest.TestCase.assertRegexpMatches` on Python 2. - - Advanced - Customizing renames <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -- cgit v1.2.1 From ba9a72d863d504293de42e4636ea0f805cd4b2af Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 2 Jan 2015 09:30:00 -0600 Subject: add Tim Graham --- CONTRIBUTORS | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 0cbd0a4..1c8181f 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -10,6 +10,7 @@ Jason R. Coombs Julien Danjou Ben Darnell Ben Davis +Tim Graham Joshua Harlow Anselm Kruis Alexander Lukanin -- cgit v1.2.1 From 3acb0acc6d7fc03f53fd8568ececb0db5b56a436 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 2 Jan 2015 09:30:30 -0600 Subject: remove currentmodule directive that is no longer needed --- documentation/index.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/documentation/index.rst b/documentation/index.rst index 806504e..db47905 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -440,8 +440,6 @@ string data in all Python versions. unittest assertions >>>>>>>>>>>>>>>>>>> -.. currentmodule:: six - Contains compatibility shims for unittest assertions that have been renamed. The parameters are the same as their aliases, but you must pass the test method as the first argument. For example:: -- cgit v1.2.1 From 678cfb323729045c73ce405052955c9b0e4edc86 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 2 Jan 2015 09:31:42 -0600 Subject: note that assertCountEqual is newish --- documentation/index.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/documentation/index.rst b/documentation/index.rst index db47905..3317596 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -440,7 +440,7 @@ string data in all Python versions. unittest assertions >>>>>>>>>>>>>>>>>>> -Contains compatibility shims for unittest assertions that have been renamed. +Six contains compatibility shims for unittest assertions that have been renamed. The parameters are the same as their aliases, but you must pass the test method as the first argument. For example:: @@ -455,7 +455,8 @@ as the first argument. For example:: .. function:: assertCountEqual() Alias for :meth:`~py3:unittest.TestCase.assertCountEqual` on Python 3 and - :meth:`~py2:unittest.TestCase.assertItemsEqual` on Python 2. + :meth:`~py2:unittest.TestCase.assertItemsEqual` on Python 2. This method is + only available on Python 2.7 and later. .. function:: assertRaisesRegex() -- cgit v1.2.1 From 0a7fff264df17e3982ae732e48b33d634fc4fa35 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 2 Jan 2015 09:40:53 -0600 Subject: assertRegex and assertRaisesRegex are 2.7+ only, too --- test_six.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test_six.py b/test_six.py index 4e95394..3a3faff 100644 --- a/test_six.py +++ b/test_six.py @@ -800,6 +800,7 @@ def test_assertCountEqual(): TestAssertCountEqual('test').test() +@py.test.mark.skipif("sys.version_info[:2] < (2, 7)") def test_assertRegex(): class TestAssertRegex(unittest.TestCase): def test(self): @@ -811,6 +812,7 @@ def test_assertRegex(): TestAssertRegex('test').test() +@py.test.mark.skipif("sys.version_info[:2] < (2, 7)") def test_assertRaisesRegex(): class TestAssertRaisesRegex(unittest.TestCase): def test(self): -- cgit v1.2.1 From 1aaace0e8487b54b573a9d2ea6d7ce7712b264bd Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 2 Jan 2015 09:41:55 -0600 Subject: note that the unittest asertion methods are only available on 2.7 and later --- documentation/index.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/index.rst b/documentation/index.rst index 3317596..1982070 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -451,12 +451,12 @@ as the first argument. For example:: def test(self): six.assertCountEqual(self, (1, 2), [2, 1]) +Note these functions are only available on Python 2.7 or later. .. function:: assertCountEqual() Alias for :meth:`~py3:unittest.TestCase.assertCountEqual` on Python 3 and - :meth:`~py2:unittest.TestCase.assertItemsEqual` on Python 2. This method is - only available on Python 2.7 and later. + :meth:`~py2:unittest.TestCase.assertItemsEqual` on Python 2. .. function:: assertRaisesRegex() -- cgit v1.2.1 From aa6ff181bf15eb6169097589c69238bbf3f549a0 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 2 Jan 2015 09:42:13 -0600 Subject: add space --- documentation/index.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/documentation/index.rst b/documentation/index.rst index 1982070..0755043 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -458,11 +458,13 @@ Note these functions are only available on Python 2.7 or later. Alias for :meth:`~py3:unittest.TestCase.assertCountEqual` on Python 3 and :meth:`~py2:unittest.TestCase.assertItemsEqual` on Python 2. + .. function:: assertRaisesRegex() Alias for :meth:`~py3:unittest.TestCase.assertRaisesRegex` on Python 3 and :meth:`~py2:unittest.TestCase.assertRaisesRegexp` on Python 2. + .. function:: assertRegex() Alias for :meth:`~py3:unittest.TestCase.assertRegex` on Python 3 and -- cgit v1.2.1 From c5426baee36fe4521a29b5d455efeb61573ad50c Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 2 Jan 2015 09:57:15 -0600 Subject: document python_2_unicode_compatible --- CHANGES | 3 +++ documentation/index.rst | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGES b/CHANGES index e12508a..e257d61 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,9 @@ This file lists the changes in each six version. Development version ------------------- +- Pull request #48 and issue #15: Add the `python_2_unicode_compatible` + decorator. + - Pull request #57 and issue #50: Add several compatibility methods for unittest assertions that were renamed between Python 2 and 3. diff --git a/documentation/index.rst b/documentation/index.rst index 0755043..e0ce4cc 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -437,6 +437,14 @@ string data in all Python versions. :class:`py3:io.BytesIO`. +.. decorator:: python_2_unicode_compatible + + A class decorator that takes a class defining a ``__str__`` method. On + Python 3, the decorator does nothing. On Python 2, it aliases the + ``__str__`` method to ``__unicode__`` and creates a new ``__str__`` method + that returns the result of ``__unicode__()`` encoded with UTF-8. + + unittest assertions >>>>>>>>>>>>>>>>>>> -- cgit v1.2.1 From c533d779727e0bad7ad5a362d7a337a0905e78c7 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 2 Jan 2015 09:58:16 -0600 Subject: add Thomas Grainger --- CONTRIBUTORS | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 1c8181f..81c2eae 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -11,6 +11,7 @@ Julien Danjou Ben Darnell Ben Davis Tim Graham +Thomas Grainger Joshua Harlow Anselm Kruis Alexander Lukanin -- cgit v1.2.1 From 23f2567ee94d0a1eebdd8afe6f11140815fcf094 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 2 Jan 2015 10:00:10 -0600 Subject: use decorator directive for add_metaclass and wraps --- documentation/index.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/index.rst b/documentation/index.rst index e0ce4cc..627862a 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -243,7 +243,7 @@ functions and methods is the stdlib :mod:`py3:inspect` module. aliased to :class:`py3:object`.) -.. function:: wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS, updated=functools.WRAPPER_UPDATES) +.. decorator:: wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS, updated=functools.WRAPPER_UPDATES) This is exactly the :func:`py3:functools.wraps` decorator, but it sets the ``__wrapped__`` attribute on what it decorates as :func:`py3:functools.wraps` @@ -320,7 +320,7 @@ Python 2 and 3. decorator. -.. function:: add_metaclass(metaclass) +.. decorator:: add_metaclass(metaclass) Class decorator that replaces a normally-constructed class with a metaclass-constructed one. Example usage: :: -- cgit v1.2.1 From 1ba12e99db60c3d5703f72b20e4d3513b375414a Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 2 Jan 2015 10:20:40 -0600 Subject: support the flush parameter of print_ (fixes #106) --- CHANGES | 2 ++ documentation/index.rst | 5 +++-- six.py | 8 ++++++++ test_six.py | 11 +++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index e257d61..adef9ea 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,8 @@ This file lists the changes in each six version. Development version ------------------- +- Issue #106: Support the `flush` parameter to `six.print_`. + - Pull request #48 and issue #15: Add the `python_2_unicode_compatible` decorator. diff --git a/documentation/index.rst b/documentation/index.rst index 627862a..1f27400 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -270,10 +270,11 @@ Python 2 and 3. :func:`exec` with them should be avoided. -.. function:: print_(*args, *, file=sys.stdout, end="\\n", sep=" ") +.. function:: print_(*args, *, file=sys.stdout, end="\\n", sep=" ", flush=False) Print *args* into *file*. Each argument will be separated with *sep* and - *end* will be written to the file after the last argument is printed. + *end* will be written to the file after the last argument is printed. If + *flush* is true, ``file.flush()`` will be called after all data is written. .. note:: diff --git a/six.py b/six.py index b54590f..f121064 100644 --- a/six.py +++ b/six.py @@ -740,6 +740,14 @@ if print_ is None: write(sep) write(arg) write(end) +if sys.version_info[:2] < (3, 3): + _print = print_ + def print_(*args, **kwargs): + fp = kwargs.get("file", sys.stdout) + flush = kwargs.pop("flush", False) + _print(*args, **kwargs) + if flush and fp is not None: + fp.flush() _add_doc(reraise, """Reraise an exception.""") diff --git a/test_six.py b/test_six.py index 3a3faff..76a8ccb 100644 --- a/test_six.py +++ b/test_six.py @@ -636,6 +636,17 @@ def test_print_(): out = six.StringIO() six.print_(None, file=out) assert out.getvalue() == "None\n" + class FlushableStringIO(six.StringIO): + def __init__(self): + six.StringIO.__init__(self) + self.flushed = False + def flush(self): + self.flushed = True + out = FlushableStringIO() + six.print_("Hello", file=out) + assert not out.flushed + six.print_("Hello", file=out, flush=True) + assert out.flushed @py.test.mark.skipif("sys.version_info[:2] >= (2, 6)") -- cgit v1.2.1 From c892030caef631cb580286779d4ebe2c67e7886d Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 2 Jan 2015 10:26:04 -0600 Subject: fix raise_from on py3.2 --- six.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/six.py b/six.py index f121064..a695328 100644 --- a/six.py +++ b/six.py @@ -677,7 +677,13 @@ else: """) -if sys.version_info > (3, 2): +if sys.version_info[:2] == (3, 2): + exec_("""def raise_from(value, from_value): + if from_value is None: + raise value + raise value from from_value +""") +elif sys.version_info[:2] > (3, 2): exec_("""def raise_from(value, from_value): raise value from from_value """) -- cgit v1.2.1 From 0de1b545fb42cb312199280d532c2831966a6b29 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 2 Jan 2015 10:31:42 -0600 Subject: update copyright year --- LICENSE | 2 +- documentation/conf.py | 2 +- six.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LICENSE b/LICENSE index d76e024..e558f9d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2010-2014 Benjamin Peterson +Copyright (c) 2010-2015 Benjamin Peterson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/documentation/conf.py b/documentation/conf.py index 7e54287..0215bdd 100644 --- a/documentation/conf.py +++ b/documentation/conf.py @@ -33,7 +33,7 @@ master_doc = "index" # General information about the project. project = u"six" -copyright = u"2010-2014, Benjamin Peterson" +copyright = u"2010-2015, Benjamin Peterson" sys.path.append(os.path.abspath(os.path.join(".", ".."))) from six import __version__ as six_version diff --git a/six.py b/six.py index a695328..b37a6df 100644 --- a/six.py +++ b/six.py @@ -1,6 +1,6 @@ """Utilities for writing code that runs on Python 2 and 3""" -# Copyright (c) 2010-2014 Benjamin Peterson +# Copyright (c) 2010-2015 Benjamin Peterson # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal -- cgit v1.2.1 From 8cfbff6b764af86d825086fa1637aa009e90d75a Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 2 Jan 2015 10:34:20 -0600 Subject: six 1.9.0 --- CHANGES | 4 ++-- six.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index adef9ea..4b9425f 100644 --- a/CHANGES +++ b/CHANGES @@ -3,8 +3,8 @@ Changelog for six This file lists the changes in each six version. -Development version -------------------- +1.9.0 +----- - Issue #106: Support the `flush` parameter to `six.print_`. diff --git a/six.py b/six.py index b37a6df..ffa3fe1 100644 --- a/six.py +++ b/six.py @@ -29,7 +29,7 @@ import sys import types __author__ = "Benjamin Peterson " -__version__ = "1.8.0" +__version__ = "1.9.0" # Useful for very coarse version differentiation. -- cgit v1.2.1 -- cgit v1.2.1 From b24e1d723805c67b75697666644a91e94f70bb62 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Mon, 5 Jan 2015 12:19:26 -0600 Subject: we no longer support python 2.5 --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 32bab7c..2a22717 100644 --- a/README +++ b/README @@ -3,7 +3,7 @@ for smoothing over the differences between the Python versions with the goal of writing Python code that is compatible on both Python versions. See the documentation for more information on what is provided. -Six supports every Python version since 2.5. It is contained in only one Python +Six supports every Python version since 2.6. It is contained in only one Python file, so it can be easily copied into your project. (The copyright and license notice must be retained.) -- cgit v1.2.1 From 6e1839a01ede7010ff130eab058c2ddd6d71902d Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Mon, 5 Jan 2015 12:20:14 -0600 Subject: remove python 2.5 from tox.ini --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index b29b31a..00d4c44 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=py25,py26,py27,py31,py32,py33,py34,pypy +envlist=py26,py27,py31,py32,py33,py34,pypy indexserver= default = http://pypi.python.org/simple testrun = http://pypi.testrun.org -- cgit v1.2.1 From 060093cb093c8dc237ad11ec681c7e0f9ed97cc2 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Wed, 21 Jan 2015 16:56:00 +0200 Subject: Issue #112: six.moves.reload_module now uses importlib module on Python 3.4+. --- CHANGES | 3 +++ documentation/index.rst | 4 +++- six.py | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 4b9425f..3434ff5 100644 --- a/CHANGES +++ b/CHANGES @@ -26,6 +26,9 @@ This file lists the changes in each six version. - Pull request #51: Add `six.view(keys|values|itmes)`, which provide dictionary views on Python 2.7+. +- Issue #112: `six.moves.reload_module` now uses the importlib module on + Python 3.4+. + 1.8.0 ----- diff --git a/documentation/index.rst b/documentation/index.rst index 1f27400..a8632e7 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -598,7 +598,9 @@ Supported renames: +------------------------------+-------------------------------------+-------------------------------------+ | ``reduce`` | :func:`py2:reduce` | :func:`py3:functools.reduce` | +------------------------------+-------------------------------------+-------------------------------------+ -| ``reload_module`` | :func:`py2:reload` | :func:`py3:imp.reload` | +| ``reload_module`` | :func:`py2:reload` | :func:`py3:imp.reload`, | +| | | :func:`py3:importlib.reload` | +| | | on Python 3.4+ | +------------------------------+-------------------------------------+-------------------------------------+ | ``reprlib`` | :mod:`py2:repr` | :mod:`py3:reprlib` | +------------------------------+-------------------------------------+-------------------------------------+ diff --git a/six.py b/six.py index ffa3fe1..16a26c8 100644 --- a/six.py +++ b/six.py @@ -35,6 +35,7 @@ __version__ = "1.9.0" # Useful for very coarse version differentiation. PY2 = sys.version_info[0] == 2 PY3 = sys.version_info[0] == 3 +PY34 = sys.version_info[0:2] >= (3, 4) if PY3: string_types = str, @@ -235,7 +236,7 @@ _moved_attributes = [ MovedAttribute("intern", "__builtin__", "sys"), MovedAttribute("map", "itertools", "builtins", "imap", "map"), MovedAttribute("range", "__builtin__", "builtins", "xrange", "range"), - MovedAttribute("reload_module", "__builtin__", "imp", "reload"), + MovedAttribute("reload_module", "__builtin__", "importlib" if PY34 else "imp", "reload"), MovedAttribute("reduce", "__builtin__", "functools"), MovedAttribute("shlex_quote", "pipes", "shlex", "quote"), MovedAttribute("StringIO", "StringIO", "io"), -- cgit v1.2.1 From b01d8d7141916c3e7e131d3e9d9947d0ae064fef Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Wed, 21 Jan 2015 11:51:32 -0500 Subject: add Berker --- CONTRIBUTORS | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 81c2eae..206bb0f 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -16,6 +16,7 @@ Joshua Harlow Anselm Kruis Alexander Lukanin James Mills +Berker Peksag Sridhar Ratnakumar Erik Rose Peter Ruibal -- cgit v1.2.1 From 8a388d3812535bfbdbe6e4629d33e1cb69179dcc Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 22 Jan 2015 10:06:10 -0500 Subject: fix tests on Python 3.1 (fixes #113) Patch by Arfrever Frehtes Taifersar Arahesis. --- six.py | 8 ++++++-- test_six.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/six.py b/six.py index 16a26c8..b7650b0 100644 --- a/six.py +++ b/six.py @@ -612,8 +612,12 @@ if PY3: StringIO = io.StringIO BytesIO = io.BytesIO _assertCountEqual = "assertCountEqual" - _assertRaisesRegex = "assertRaisesRegex" - _assertRegex = "assertRegex" + if sys.version_info[1] <= 1: + _assertRaisesRegex = "assertRaisesRegexp" + _assertRegex = "assertRegexpMatches" + else: + _assertRaisesRegex = "assertRaisesRegex" + _assertRegex = "assertRegex" else: def b(s): return s diff --git a/test_six.py b/test_six.py index 76a8ccb..f33f882 100644 --- a/test_six.py +++ b/test_six.py @@ -799,7 +799,7 @@ def test_add_metaclass(): assert type(MySlotsWeakref) is Meta -@py.test.mark.skipif("sys.version_info[:2] < (2, 7)") +@py.test.mark.skipif("sys.version_info[:2] < (2, 7) or sys.version_info[:2] in ((3, 0), (3, 1))") def test_assertCountEqual(): class TestAssertCountEqual(unittest.TestCase): def test(self): -- cgit v1.2.1