diff options
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | six.py | 9 | ||||
-rw-r--r-- | test_six.py | 2 |
3 files changed, 6 insertions, 7 deletions
@@ -6,6 +6,8 @@ This file lists the changes in each six version. Development version ------------------- +- Issue #122: Improve the performance of `six.int2byte` on Python 3. + - Pull request #55 and issue #99: Don't add the `winreg` module to `six.moves` on non-Windows platforms. @@ -622,12 +622,9 @@ if PY3: def u(s): return s unichr = chr - if sys.version_info[1] <= 1: - def int2byte(i): - return bytes((i,)) - else: - # This is about 2x faster than the implementation above on 3.2+ - int2byte = operator.methodcaller("to_bytes", 1, "big") + import struct + int2byte = struct.Struct(">B").pack + del struct byte2int = operator.itemgetter(0) indexbytes = operator.getitem iterbytes = iter diff --git a/test_six.py b/test_six.py index 060a966..3e57f49 100644 --- a/test_six.py +++ b/test_six.py @@ -511,7 +511,7 @@ def test_unichr(): def test_int2byte(): assert six.int2byte(3) == six.b("\x03") - py.test.raises((OverflowError, ValueError), six.int2byte, 256) + py.test.raises(Exception, six.int2byte, 256) def test_byte2int(): |