Skip to content

Commit 0b1553f

Browse files
committed
explicitly fix memoryview.hex
1 parent 0488d21 commit 0b1553f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Lib/test/test_memoryview.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
are in test_buffer.
55
"""
66

7-
import contextlib
87
import unittest
98
import test.support
109
import sys
@@ -455,9 +454,7 @@ def __len__(self):
455454
ba.clear()
456455
return 1
457456

458-
# The following should not crash but it may not necessarily raise.
459-
with contextlib.suppress(BufferError):
460-
mv.hex(S(b':'))
457+
self.assertRaises(BufferError, mv.hex, S(b':'))
461458

462459

463460
# Variations on source objects for the buffer: bytes-like objects, then arrays

Objects/memoryobject.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2349,7 +2349,10 @@ memoryview_hex_impl(PyMemoryViewObject *self, PyObject *sep,
23492349
CHECK_RELEASED(self);
23502350

23512351
if (MV_C_CONTIGUOUS(self->flags)) {
2352-
return _Py_strhex_with_sep(src->buf, src->len, sep, bytes_per_sep);
2352+
self->exports++;
2353+
PyObject *ret = _Py_strhex_with_sep(src->buf, src->len, sep, bytes_per_sep);
2354+
self->exports--;
2355+
return ret;
23532356
}
23542357

23552358
PyBytesWriter *writer = PyBytesWriter_Create(src->len);

0 commit comments

Comments
 (0)