Skip to content

Bindings type checking too strict #373

@rogerbinns

Description

@rogerbinns

Bindings for cursor.execute/executemany can conceptually either be a dictionary (lookup by key) or a sequence (lookup by position).

Currently PyDict_Check is used to determine if it is a dictionary, otherwise PySequence_Fast is used for positional access.

Because PyDict_Check only looks for dict subclasses, it means that UserDict won't work. The apparent solution of PyMapping_Check returns True for UserDict, but also for lists and tuples.

For reference, this is what the builtin _sqlite3 module does

Treat as not a dictionary if:

PyTuple_CheckExact(parameters) || PyList_CheckExact(parameters) 
|| (!PyDict_Check(parameters) && PySequence_Check(parameters))

Otherwise treat as dictionary if:

PyDict_Check(parameters)

Otherwise error

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions