8000 fallback: Remove old buffer protocol support (#384) · ossdev07/msgpack-python@de32048 · GitHub
[go: up one dir, main page]

Skip to content

Commit de32048

Browse files
authored
fallback: Remove old buffer protocol support (msgpack#384)
1 parent 9f4b2d5 commit de32048

File tree

2 files changed

+5
-19
lines changed

2 files changed

+5
-19
lines changed

msgpack/fallback.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,7 @@ def _check_type_strict(obj, t, type=type, tuple=tuple):
111111

112112

113113
def _get_data_from_buffer(obj):
114-
try:
115-
view = memoryview(obj)
116-
except TypeError:
117-
# try to use legacy buffer protocol if 2.7, otherwise re-raise
118-
if PY2:
119-
view = memoryview(buffer(obj))
120-
warnings.warn(
121-
"using old buffer interface to unpack %s; "
122-
"this leads to unpacking errors if slicing is used and "
123-
"will be removed in a future version" % type(obj),
124-
RuntimeWarning,
125-
stacklevel=3,
126-
)
127-
else:
128-
raise
114+
view = memoryview(obj)
129115
if view.itemsize != 1:
130116
raise ValueError("cannot unpack from multi-byte object")
131117
return view

test/test_buffer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#!/usr/bin/env python
22
# coding: utf-8
33

4+
import sys
5+
import pytest
46
from msgpack import packb, unpackb
57

68

9+
@pytest.mark.skipif(sys.version_info[0] == 2, reason="Python 2 is not supported")
710
def test_unpack_buffer():
811
from array import array
912

1013
buf = array("b")
11-
try:
12-
buf.frombytes(packb((b"foo", b"bar")))
13-
except AttributeError: # PY2
14-
buf.fromstring(packb((b"foo", b"bar")))
14+
buf.frombytes(packb((b"foo", b"bar")))
1515
obj = unpackb(buf, use_list=1)
1616
assert [b"foo", b"bar"] == obj
1717

0 commit comments

Comments
 (0)
0