mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-21071: struct.Struct.format type is now str (#845)
This commit is contained in:
parent
a4b091e135
commit
f87b85f808
5 changed files with 19 additions and 2 deletions
|
@ -443,6 +443,9 @@ The :mod:`struct` module also defines the following type:
|
||||||
|
|
||||||
The format string used to construct this Struct object.
|
The format string used to construct this Struct object.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.7
|
||||||
|
The format string type is now :class:`str` instead of :class:`bytes`.
|
||||||
|
|
||||||
.. attribute:: size
|
.. attribute:: size
|
||||||
|
|
||||||
The calculated size of the struct (and hence of the bytes object produced
|
The calculated size of the struct (and hence of the bytes object produced
|
||||||
|
|
|
@ -429,6 +429,9 @@ Changes in the Python API
|
||||||
``makedirs()``.
|
``makedirs()``.
|
||||||
(Contributed by Serhiy Storchaka in :issue:`19930`.)
|
(Contributed by Serhiy Storchaka in :issue:`19930`.)
|
||||||
|
|
||||||
|
* The :attr:`struct.Struct.format` type is now :class:`str` instead of
|
||||||
|
:class:`bytes`. (Contributed by Victor Stinner in :issue:`21071`.)
|
||||||
|
|
||||||
|
|
||||||
CPython bytecode changes
|
CPython bytecode changes
|
||||||
------------------------
|
------------------------
|
||||||
|
|
|
@ -618,6 +618,14 @@ class StructTest(unittest.TestCase):
|
||||||
# Shouldn't crash.
|
# Shouldn't crash.
|
||||||
self.assertEqual(struct.unpack(b'b', b'a'), (b'a'[0],))
|
self.assertEqual(struct.unpack(b'b', b'a'), (b'a'[0],))
|
||||||
|
|
||||||
|
def test_format_attr(self):
|
||||||
|
s = struct.Struct('=i2H')
|
||||||
|
self.assertEqual(s.format, '=i2H')
|
||||||
|
|
||||||
|
# use a bytes string
|
||||||
|
s2 = struct.Struct(s.format.encode())
|
||||||
|
self.assertEqual(s2.format, s.format)
|
||||||
|
|
||||||
|
|
||||||
class UnpackIteratorTest(unittest.TestCase):
|
class UnpackIteratorTest(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -374,6 +374,9 @@ Extension Modules
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- bpo-21071: struct.Struct.format type is now :class:`str` instead of
|
||||||
|
:class:`bytes`.
|
||||||
|
|
||||||
- bpo-29212: Fix concurrent.futures.thread.ThreadPoolExecutor threads to have
|
- bpo-29212: Fix concurrent.futures.thread.ThreadPoolExecutor threads to have
|
||||||
a non repr() based thread name by default when no thread_name_prefix is
|
a non repr() based thread name by default when no thread_name_prefix is
|
||||||
supplied. They will now identify themselves as "ThreadPoolExecutor-y_n".
|
supplied. They will now identify themselves as "ThreadPoolExecutor-y_n".
|
||||||
|
|
|
@ -1957,8 +1957,8 @@ s_pack_into(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames
|
||||||
static PyObject *
|
static PyObject *
|
||||||
s_get_format(PyStructObject *self, void *unused)
|
s_get_format(PyStructObject *self, void *unused)
|
||||||
{
|
{
|
||||||
Py_INCREF(self->s_format);
|
return PyUnicode_FromStringAndSize(PyBytes_AS_STRING(self->s_format),
|
||||||
return self->s_format;
|
PyBytes_GET_SIZE(self->s_format));
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue