Should sqlite3.Row be more dict-like?

.__contains__() for a mapping/sequence object is always ambiguous, since default is to search values for sequences and keys for mappings.

Now, the in operator first looks for the .__contains__() method and then falls back to iterating over the object until it finds the value or the iterator is exhausted (see PySequence_Contains() et al.), so the current behavior of x in sqlite3.Row() is to search for values, not keys.

You may want to implement the sq_contains slot for Row objects as an optimization, but I doubt that this is worth the hassle, since I don’t think that people will use in on Row objects a lot - esp. not since it’s ambiguous.

I’d simply close the issue.

3 Likes