Skip to content

sqlite3.Connection.execute() exposes unrepresentable Argument Clinic default #155952

Description

@lpyu001

Bug report

Bug description:

Summary

sqlite3.Connection.execute() currently exposes this text signature:

execute($self, sql, parameters=<unrepresentable>, /)

As a result, inspect.signature(sqlite3.Connection.execute) raises
ValueError. The correct Python default is (), while the C wrapper must
continue using NULL when the argument is omitted.

Evidence

The current Clinic definition in Modules/_sqlite/connection.c is:

parameters: object = NULL

When the argument is omitted, _pysqlite_query_execute() explicitly converts
the C NULL sentinel to an empty tuple:

if (second_argument == NULL) {
    second_argument = PyTuple_New(0);
}

Therefore these calls are equivalent:

con.execute("select 42")
con.execute("select 42", ())

The public documentation already specifies:

execute(sql, parameters=(), /)

sqlite3.Cursor.execute() also uses the correct Clinic pattern:

parameters: object(c_default="NULL") = ()

Reproduction

import inspect
import sqlite3

inspect.signature(sqlite3.Connection.execute)
# ValueError: builtin has invalid signature

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Labels

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions