]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-43916: Add Py_TPFLAGS_DISALLOW_INSTANTIATION type flag (GH-25721)
authorVictor Stinner <vstinner@python.org>
Fri, 30 Apr 2021 10:46:15 +0000 (12:46 +0200)
committerGitHub <noreply@github.com>
Fri, 30 Apr 2021 10:46:15 +0000 (12:46 +0200)
commit3bb09947ec4837de75532e21dd4bd25db0a1f1b7
tree46469716b18eda1c8af7c311b6187fda39a146c1
parentb73b5fb9ea08156991a065c1696e8d8cf7622482
bpo-43916: Add Py_TPFLAGS_DISALLOW_INSTANTIATION type flag (GH-25721)

Add a new Py_TPFLAGS_DISALLOW_INSTANTIATION type flag to disallow
creating type instances: set tp_new to NULL and don't create the
"__new__" key in the type dictionary.

The flag is set automatically on static types if tp_base is NULL or
&PyBaseObject_Type and tp_new is NULL.

Use the flag on the following types:

* _curses.ncurses_version type
* _curses_panel.panel
* _tkinter.Tcl_Obj
* _tkinter.tkapp
* _tkinter.tktimertoken
* _xxsubinterpretersmodule.ChannelID
* sys.flags type
* sys.getwindowsversion() type
* sys.version_info type

Update MyStr example in the C API documentation to use
Py_TPFLAGS_DISALLOW_INSTANTIATION.

Add _PyStructSequence_InitType() function to create a structseq type
with the Py_TPFLAGS_DISALLOW_INSTANTIATION flag set.

type_new() calls _PyType_CheckConsistency() at exit.
13 files changed:
Doc/c-api/typeobj.rst
Doc/whatsnew/3.10.rst
Include/object.h
Include/structseq.h
Lib/test/test_sys.py
Misc/NEWS.d/next/C API/2021-04-29-17-35-48.bpo-43916.wvWt23.rst [new file with mode: 0644]
Modules/_curses_panel.c
Modules/_cursesmodule.c
Modules/_tkinter.c
Modules/_xxsubinterpretersmodule.c
Objects/structseq.c
Objects/typeobject.c
Python/sysmodule.c