mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-06 17:59:52 +00:00
Drop Python 3.6 support (#543)
The following steps have been taken: 1. Black was updated to latest version. The code has been formatted with the new version. 2. The pyupgrade utility is installed. This helped to remove all the code that was needed to support Python < 3.7. Fix #541. Co-authored-by: Inada Naoki <songofacandy@gmail.com>
This commit is contained in:
parent
feec06206c
commit
c8d0751fe3
23 changed files with 60 additions and 119 deletions
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
import sys
|
||||
import pytest
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
from msgpack import packb, unpackb
|
||||
|
||||
|
||||
def check(length, obj, use_bin_type=True):
|
||||
v = packb(obj, use_bin_type=use_bin_type)
|
||||
assert len(v) == length, "%r length should be %r but get %r" % (obj, length, len(v))
|
||||
assert len(v) == length, f"{obj!r} length should be {length!r} but get {len(v)!r}"
|
||||
assert unpackb(v, use_list=0, raw=not use_bin_type) == obj
|
||||
|
||||
|
||||
|
|
@ -120,11 +119,11 @@ def test_match():
|
|||
),
|
||||
({}, b"\x80"),
|
||||
(
|
||||
dict([(x, x) for x in range(15)]),
|
||||
{x: x for x in range(15)},
|
||||
b"\x8f\x00\x00\x01\x01\x02\x02\x03\x03\x04\x04\x05\x05\x06\x06\x07\x07\x08\x08\t\t\n\n\x0b\x0b\x0c\x0c\r\r\x0e\x0e",
|
||||
),
|
||||
(
|
||||
dict([(x, x) for x in range(16)]),
|
||||
{x: x for x in range(16)},
|
||||
b"\xde\x00\x10\x00\x00\x01\x01\x02\x02\x03\x03\x04\x04\x05\x05\x06\x06\x07\x07\x08\x08\t\t\n\n\x0b\x0b\x0c\x0c\r\r\x0e\x0e\x0f\x0f",
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
from pytest import raises
|
||||
from msgpack import packb, unpackb, Unpacker, FormatError, StackError, OutOfData
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
from __future__ import print_function
|
||||
import array
|
||||
import msgpack
|
||||
from msgpack import ExtType
|
||||
|
|
@ -17,9 +16,7 @@ def test_pack_ext_type():
|
|||
assert p(b"A" * 16) == b"\xd8\x42" + b"A" * 16 # fixext 16
|
||||
assert p(b"ABC") == b"\xc7\x03\x42ABC" # ext 8
|
||||
assert p(b"A" * 0x0123) == b"\xc8\x01\x23\x42" + b"A" * 0x0123 # ext 16
|
||||
assert (
|
||||
p(b"A" * 0x00012345) == b"\xc9\x00\x01\x23\x45\x42" + b"A" * 0x00012345
|
||||
) # ext 32
|
||||
assert p(b"A" * 0x00012345) == b"\xc9\x00\x01\x23\x45\x42" + b"A" * 0x00012345 # ext 32
|
||||
|
||||
|
||||
def test_unpack_ext_type():
|
||||
|
|
@ -49,7 +46,7 @@ def test_extension_type():
|
|||
except AttributeError:
|
||||
data = obj.tostring()
|
||||
return ExtType(typecode, data)
|
||||
raise TypeError("Unknown type object %r" % (obj,))
|
||||
raise TypeError(f"Unknown type object {obj!r}")
|
||||
|
||||
def ext_hook(code, data):
|
||||
print("ext_hook called", code, data)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
from msgpack import unpackb
|
||||
|
||||
|
|
@ -25,9 +24,7 @@ def testFixRaw():
|
|||
|
||||
|
||||
def testFixMap():
|
||||
check(
|
||||
b"\x82\xc2\x81\xc0\xc0\xc3\x81\xc0\x80", {False: {None: None}, True: {None: {}}}
|
||||
)
|
||||
check(b"\x82\xc2\x81\xc0\xc0\xc3\x81\xc0\x80", {False: {None: None}, True: {None: {}}})
|
||||
|
||||
|
||||
def testUnsignedInt():
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
import pytest
|
||||
|
||||
from msgpack import (
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
import pytest
|
||||
from array import array
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
# coding: utf-8
|
||||
|
||||
from msgpack import packb, unpackb, ExtType
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
from pytest import raises
|
||||
from msgpack import packb, unpackb
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
from collections import OrderedDict
|
||||
from io import BytesIO
|
||||
|
|
@ -81,9 +79,7 @@ def testPackByteArrays():
|
|||
|
||||
|
||||
def testIgnoreUnicodeErrors():
|
||||
re = unpackb(
|
||||
packb(b"abc\xeddef", use_bin_type=False), raw=False, unicode_errors="ignore"
|
||||
)
|
||||
re = unpackb(packb(b"abc\xeddef", use_bin_type=False), raw=False, unicode_errors="ignore")
|
||||
assert re == "abcdef"
|
||||
|
||||
|
||||
|
|
@ -108,8 +104,8 @@ def testDecodeBinary():
|
|||
|
||||
|
||||
def testPackFloat():
|
||||
assert packb(1.0, use_single_float=True) == b"\xca" + struct.pack(str(">f"), 1.0)
|
||||
assert packb(1.0, use_single_float=False) == b"\xcb" + struct.pack(str(">d"), 1.0)
|
||||
assert packb(1.0, use_single_float=True) == b"\xca" + struct.pack(">f", 1.0)
|
||||
assert packb(1.0, use_single_float=False) == b"\xcb" + struct.pack(">d", 1.0)
|
||||
|
||||
|
||||
def testArraySize(sizes=[0, 5, 50, 1000]):
|
||||
|
|
@ -154,7 +150,7 @@ def testMapSize(sizes=[0, 5, 50, 1000]):
|
|||
bio.seek(0)
|
||||
unpacker = Unpacker(bio, strict_map_key=False)
|
||||
for size in sizes:
|
||||
assert unpacker.unpack() == dict((i, i * 2) for i in range(size))
|
||||
assert unpacker.unpack() == {i: i * 2 for i in range(size)}
|
||||
|
||||
|
||||
def test_odict():
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
import io
|
||||
import msgpack
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
import io
|
||||
from msgpack import Unpacker, BufferFull
|
||||
from msgpack import pack, packb
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
# coding: utf-8
|
||||
|
||||
from collections import namedtuple
|
||||
from msgpack import packb, unpackb, ExtType
|
||||
|
||||
|
|
@ -10,7 +8,7 @@ def test_namedtuple():
|
|||
def default(o):
|
||||
if isinstance(o, T):
|
||||
return dict(o._asdict())
|
||||
raise TypeError("Unsupported type %s" % (type(o),))
|
||||
raise TypeError(f"Unsupported type {type(o)}")
|
||||
|
||||
packed = packb(T(1, 42), strict_types=True, use_bin_type=True, default=default)
|
||||
unpacked = unpackb(packed, raw=False)
|
||||
|
|
@ -23,7 +21,7 @@ def test_tuple():
|
|||
def default(o):
|
||||
if isinstance(o, tuple):
|
||||
return {"__type__": "tuple", "value": list(o)}
|
||||
raise TypeError("Unsupported type %s" % (type(o),))
|
||||
raise TypeError(f"Unsupported type {type(o)}")
|
||||
|
||||
def convert(o):
|
||||
if o.get("__type__") == "tuple":
|
||||
|
|
@ -44,9 +42,7 @@ def test_tuple_ext():
|
|||
def default(o):
|
||||
if isinstance(o, tuple):
|
||||
# Convert to list and pack
|
||||
payload = packb(
|
||||
list(o), strict_types=True, use_bin_type=True, default=default
|
||||
)
|
||||
payload = packb(list(o), strict_types=True, use_bin_type=True, default=default)
|
||||
return ExtType(MSGPACK_EXT_TYPE_TUPLE, payload)
|
||||
raise TypeError(repr(o))
|
||||
|
||||
|
|
@ -54,7 +50,7 @@ def test_tuple_ext():
|
|||
if code == MSGPACK_EXT_TYPE_TUPLE:
|
||||
# Unpack and convert to tuple
|
||||
return tuple(unpackb(payload, raw=False, ext_hook=convert))
|
||||
raise ValueError("Unknown Ext code {}".format(code))
|
||||
raise ValueError(f"Unknown Ext code {code}")
|
||||
|
||||
data = packb(t, strict_types=True, use_bin_type=True, default=default)
|
||||
expected = unpackb(data, raw=False, ext_hook=convert)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
from msgpack import packb, unpackb
|
||||
from collections import namedtuple
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ def test_unpacker_hook_refcnt():
|
|||
def test_unpacker_ext_hook():
|
||||
class MyUnpacker(Unpacker):
|
||||
def __init__(self):
|
||||
super(MyUnpacker, self).__init__(ext_hook=self._hook, raw=False)
|
||||
super().__init__(ext_hook=self._hook, raw=False)
|
||||
|
||||
def _hook(self, code, data):
|
||||
if code == 1:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue