diff -r 1c38457da5a1 Doc/library/sqlite3.rst --- a/Doc/library/sqlite3.rst Thu Aug 25 21:12:16 2016 -0700 +++ b/Doc/library/sqlite3.rst Fri Aug 26 20:36:42 2016 +0800 @@ -285,9 +285,9 @@ .. versionadded:: 3.2 - .. method:: cursor([cursorClass]) + .. method:: cursor(factory=sqlite3.Cursor) - The cursor method accepts a single optional parameter *cursorClass*. If + The cursor method accepts a single keyword parameter *factory*. If supplied, this must be a custom cursor class that extends :class:`sqlite3.Cursor`. diff -r 1c38457da5a1 Lib/sqlite3/test/factory.py --- a/Lib/sqlite3/test/factory.py Thu Aug 25 21:12:16 2016 -0700 +++ b/Lib/sqlite3/test/factory.py Fri Aug 26 20:36:42 2016 +0800 @@ -60,6 +60,11 @@ def CheckIsInstance(self): cur = self.con.cursor(factory=MyCursor) self.assertIsInstance(cur, MyCursor) + cur = self.con.cursor() + self.assertIsInstance(cur, sqlite.Cursor) + + def CheckInvalidFactory(self): + self.assertRaises(TypeError, self.con.cursor, 'abcdef') class RowFactoryTestsBackwardsCompat(unittest.TestCase): def setUp(self): @@ -185,7 +190,7 @@ # segmentation fault. class FakeCursor(str): __class__ = sqlite.Cursor - cur = self.con.cursor(factory=FakeCursor) + cur = FakeCursor() self.assertRaises(TypeError, sqlite.Row, cur, ()) def tearDown(self): diff -r 1c38457da5a1 Modules/_sqlite/connection.c --- a/Modules/_sqlite/connection.c Thu Aug 25 21:12:16 2016 -0700 +++ b/Modules/_sqlite/connection.c Fri Aug 26 20:36:42 2016 +0800 @@ -300,7 +300,7 @@ PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) { - static char *kwlist[] = {"factory", NULL, NULL}; + static char *kwlist[] = {"factory", NULL}; PyObject* factory = NULL; PyObject* cursor; @@ -309,6 +309,15 @@ return NULL; } + if (factory && + _PyObject_RealIsSubclass(factory, + (PyObject *)&pysqlite_CursorType) <= 0) { + PyErr_Format(PyExc_TypeError, + "factory must be %s", + pysqlite_CursorType.tp_name); + return NULL; + } + if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) { return NULL; }