[issue43916] Mark static types newly converted to heap types as immutable: add Py_TPFLAGS_DISALLOW_INSTANTIATION type flag

STINNER Victor report at bugs.python.org
Fri Apr 30 12:05:08 EDT 2021


STINNER Victor <vstinner at python.org> added the comment:

It seems like _sqlite3 heap types support regular instantiation and so that no change is needed.

* sqlite3.Cache

    {Py_tp_new, PyType_GenericNew},

* sqlite3.Connection

    {Py_tp_new, PyType_GenericNew},
    {Py_tp_init, pysqlite_connection_init},

* sqlite3.Cursor

    {Py_tp_new, PyType_GenericNew},
    {Py_tp_init, pysqlite_cursor_init},

* sqlite3.Node

    {Py_tp_new, PyType_GenericNew},

* sqlite3.Row

    {Py_tp_new, pysqlite_row_new},

* sqlite3.Statement

    {Py_tp_new, PyType_GenericNew},


$ ./python
Python 3.10.0a7+
>>> import _sqlite3
>>> conn=_sqlite3.Connection(":memory:")

>>> type(conn)()
TypeError: function missing required argument 'database' (pos 1)
>>> conn2 = type(conn)(":memory:")

>>> list(conn.execute("SELECT 1;"))
[(1,)]
>>> list(conn2.execute("SELECT 1;"))
[(1,)]

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43916>
_______________________________________


More information about the Python-bugs-list mailing list