Visitar URL original
GH-78724: Initialize struct.Struct in __new__ by kumaraditya303 · Pull Request #94532 · 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
remove __init__
  • Loading branch information
kumaraditya303 authored Sep 17, 2022
commit d7ce7d8d7bb399c4468a8e5f36d569a25dd263a6
3 changes: 1 addition & 2 deletions Lib/test/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,7 @@ def test__struct_Struct__new__initialized(self):
@support.cpython_only
def test__struct_Struct_subclassing(self):
class Bob(struct.Struct):
def __init__(self, format):
super().__init__(format)
pass

s = Bob("b")
s.unpack_from(b"abcd")
Expand Down
38 changes: 0 additions & 38 deletions Modules/_struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -1489,43 +1489,6 @@ Struct_impl(PyTypeObject *type, PyObject *format)
return (PyObject *)self;
}

/*[clinic input]
Struct.__init__

format: object

[clinic start generated code]*/

static int
Struct___init___impl(PyStructObject *self, PyObject *format)
/*[clinic end generated code: output=b8e80862444e92d0 input=6c10faf9b8d53954]*/
{
if (PyUnicode_Check(format)) {
format = PyUnicode_AsASCIIString(format);
if (format == NULL) {
return -1;
}
}
else {
Py_INCREF(format);
}

if (!PyBytes_Check(format)) {
Py_DECREF(format);
PyErr_Format(PyExc_TypeError,
"Struct() argument 1 must be a str or bytes object, "
"not %.200s",
_PyType_Name(Py_TYPE(format)));
return -1;
}

Py_SETREF(self->s_format, format);

if (prepare_s(self) < 0) {
return -1;
}
return 0;
}

static int
s_clear(PyStructObject *s)
Expand Down Expand Up @@ -2132,7 +2095,6 @@ static PyType_Slot PyStructType_slots[] = {
{Py_tp_members, s_members},
{Py_tp_getset, s_getsetlist},
{Py_tp_new, Struct},
{Py_tp_init, Struct___init__},
{Py_tp_alloc, PyType_GenericAlloc},
{Py_tp_free, PyObject_GC_Del},
{0, 0},
Expand Down
50 changes: 1 addition & 49 deletions Modules/clinic/_struct.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.