Visitar URL original
gh-78724: raise RuntimeError's when calling methods on non-ready Struct()'s by skirpichev · Pull Request #143643 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
revert deprecations (TBD: a separate pr)
  • Loading branch information
skirpichev committed Jan 10, 2026
commit f542173235a32e8d9dadc84b7ca7bc2af2f9a585
13 changes: 3 additions & 10 deletions Lib/test/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import unittest
import struct
import sys
import warnings
import weakref

from test import support
Expand Down Expand Up @@ -576,11 +575,7 @@ def test_Struct_reinitialization(self):
# Struct instance. This test can be used to detect the leak
# when running with regrtest -L.
s = struct.Struct('i')
with self.assertWarns(DeprecationWarning):
s.__init__('ii')
with warnings.catch_warnings():
warnings.simplefilter("error", DeprecationWarning)
self.assertRaises(DeprecationWarning, s.__init__, 'ii')
s.__init__('ii')

def check_sizeof(self, format_str, number_of_codes):
# The size of 'PyStructObject'
Expand Down Expand Up @@ -788,8 +783,7 @@ class MyStruct(struct.Struct):
def __init__(self):
super().__init__('>h')

with self.assertWarns(DeprecationWarning):
my_struct = MyStruct()
my_struct = MyStruct()
self.assertEqual(my_struct.pack(12345), b'\x30\x39')

def test_repr(self):
Expand Down Expand Up @@ -823,8 +817,7 @@ def test_endian_table_init_subinterpreters(self):
self.assertListEqual(list(results), [None] * 5)

def test_operations_on_half_initialized_Struct(self):
with self.assertWarns(DeprecationWarning):
S = struct.Struct.__new__(struct.Struct)
S = struct.Struct.__new__(struct.Struct)

spam = array.array('b', b' ')
for attr in ['iter_unpack', 'pack', 'pack_into',
Expand Down
13 changes: 0 additions & 13 deletions Modules/_struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -1763,12 +1763,6 @@ s_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *self;

if (PyTuple_GET_SIZE(args) != 1
&& PyErr_WarnEx(PyExc_DeprecationWarning,
"Struct().__new__() has one required argument", 1))
{
return NULL;
}
assert(type != NULL);
allocfunc alloc_func = PyType_GetSlot(type, Py_tp_alloc);
assert(alloc_func != NULL);
Expand Down Expand Up @@ -1802,13 +1796,6 @@ static int
Struct___init___impl(PyStructObject *self, PyObject *format)
/*[clinic end generated code: output=b8e80862444e92d0 input=192a4575a3dde802]*/
{
if (self->ready
&& PyErr_WarnEx(PyExc_DeprecationWarning,
("Explicit call of __init__() on "
"initialized Struct()"), 1))
{
return -1;
}
if (PyUnicode_Check(format)) {
format = PyUnicode_AsASCIIString(format);
if (format == NULL)
Expand Down