◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,10 @@ New Features
These functions allow to activate, deactivate and query the state of the garbage collector from C code without
having to import the :mod:`gc` module.

Porting to Python 3.10
----------------------

Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,12 @@ def test_sys_flags(self):
def assert_raise_on_new_sys_type(self, sys_attr):
# Users are intentionally prevented from creating new instances of
# sys.flags, sys.version_info, and sys.getwindowsversion.
attr_type = type(sys_attr)
with self.assertRaises(TypeError):
attr_type()
with self.assertRaises(TypeError):
attr_type.__new__(attr_type)

def test_sys_flags_no_instantiation(self):
self.assert_raise_on_new_sys_type(sys.flags)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
3 changes: 1 addition & 2 deletions Modules/_curses_panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ static PyType_Slot PyCursesPanel_Type_slots[] = {
static PyType_Spec PyCursesPanel_Type_spec = {
.name = "_curses_panel.panel",
.basicsize = sizeof(PyCursesPanelObject),
.flags = Py_TPFLAGS_DEFAULT,
.slots = PyCursesPanel_Type_slots
};

Expand Down Expand Up @@ -656,7 +656,6 @@ _curses_panel_exec(PyObject *mod)
if (state->PyCursesPanel_Type == NULL) {
return -1;
}
((PyTypeObject *)state->PyCursesPanel_Type)->tp_new = NULL;

if (PyModule_AddType(mod, state->PyCursesPanel_Type) < 0) {
return -1;
Expand Down
15 changes: 4 additions & 11 deletions Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
@@ -4793,25 +4793,18 @@ PyInit__curses(void)
#ifdef NCURSES_VERSION
/* ncurses_version */
if (NcursesVersionType.tp_name == NULL) {
if (PyStructSequence_InitType2(&NcursesVersionType,
&ncurses_version_desc) < 0)
return NULL;
}
v = make_ncurses_version();
if (v == NULL) {
return NULL;
}
PyDict_SetItemString(d, "ncurses_version", v);
Py_DECREF(v);

/* prevent user from creating new instances */
NcursesVersionType.tp_init = NULL;
NcursesVersionType.tp_new = NULL;
if (PyDict_DelItemString(NcursesVersionType.tp_dict, "__new__") < 0 &&
PyErr_ExceptionMatches(PyExc_KeyError))
{
PyErr_Clear();
}
#endif /* NCURSES_VERSION */

SetDictInt("ERR", ERR);
Expand Down
9 changes: 3 additions & 6 deletions Modules/_tkinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ static PyType_Spec PyTclObject_Type_spec = {
"_tkinter.Tcl_Obj",
sizeof(PyTclObject),
0,
Py_TPFLAGS_DEFAULT,
PyTclObject_Type_slots,
};

Expand Down Expand Up @@ -3294,7 +3294,7 @@ static PyType_Spec Tktt_Type_spec = {
"_tkinter.tktimertoken",
sizeof(TkttObject),
0,
Py_TPFLAGS_DEFAULT,
Tktt_Type_slots,
};

Expand Down Expand Up @@ -3349,7 +3349,7 @@ static PyType_Spec Tkapp_Type_spec = {
"_tkinter.tkapp",
sizeof(TkappObject),
0,
Py_TPFLAGS_DEFAULT,
Tkapp_Type_slots,
};

Expand Down @@ -3537,7 +3537,6 @@ PyInit__tkinter(void)
Py_DECREF(m);
return NULL;
}
((PyTypeObject *)o)->tp_new = NULL;
if (PyModule_AddObject(m, "TkappType", o)) {
Py_DECREF(o);
Py_DECREF(m);
Expand All @@ -3550,7 +3549,6 @@ PyInit__tkinter(void)
Py_DECREF(m);
return NULL;
}
((PyTypeObject *)o)->tp_new = NULL;
if (PyModule_AddObject(m, "TkttType", o)) {
Py_DECREF(o);
Py_DECREF(m);
Expand All @@ -3563,7 +3561,6 @@ PyInit__tkinter(void)
Py_DECREF(m);
return NULL;
}
((PyTypeObject *)o)->tp_new = NULL;
if (PyModule_AddObject(m, "Tcl_Obj", o)) {
Py_DECREF(o);
Py_DECREF(m);
Expand Down
20 changes: 6 additions & 14 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
@@ -1780,7 +1780,12 @@ static PyTypeObject ChannelIDtype = {
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
channelid_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
@@ -1791,19 +1796,6 @@ static PyTypeObject ChannelIDtype = {
0, /* tp_methods */
0, /* tp_members */
channelid_getsets, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
// Note that we do not set tp_new to channelid_new. Instead we
// set it to NULL, meaning it cannot be instantiated from Python
// code. We do this because there is a strong relationship between
// channel IDs and the channel lifecycle, so this limitation avoids
// related complications.
NULL, /* tp_new */
};


Expand Down
12 changes: 10 additions & 2 deletions Objects/structseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,10 @@ initialize_members(PyStructSequence_Desc *desc, PyMemberDef* members,
members[k].name = NULL;
}

int
PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc)
{
PyMemberDef *members;
Py_ssize_t n_members, n_unnamed_members;
Expand Down Expand Up @@ -488,7 +490,7 @@ PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc)
type->tp_base = &PyTuple_Type;
type->tp_methods = structseq_methods;
type->tp_new = structseq_new;
type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC;
type->tp_traverse = (traverseproc) structseq_traverse;

n_members = count_members(desc, &n_unnamed_members);
Expand Down Expand Up @@ -516,6 +518,12 @@ PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc)
return 0;
}

void
PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc)
{
Loading
Toggle all file notes Toggle all file annotations