Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite3.Blob indexing is not conformant with existing norms #92019

Closed
erlend-aasland opened this issue Apr 28, 2022 · 3 comments · Fixed by #92020
Closed

sqlite3.Blob indexing is not conformant with existing norms #92019

erlend-aasland opened this issue Apr 28, 2022 · 3 comments · Fixed by #92020
Labels
topic-sqlite3 type-bug An unexpected behavior, bug, or error

Comments

@erlend-aasland
Copy link
Contributor

Yesterday, @JelleZijlstra enlightened me that sqlite3.Blob indexing operate with bytes objects of length 1. This is a deviation from how bytes, bytearray, and memoryview work:

>>> bytes(b"0")[0]
48
>>> bytearray(b"0")[0]
48
>>> memoryview(b"0")[0]
48
>>> b = bytearray(b"0")
>>> b[0] = 1
>>> b[0] = b"1"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'bytes' object cannot be interpreted as an integer
>>> m = memoryview(b)
>>> m[0] = 1
>>> m[0] = b"1"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: memoryview: invalid type for format 'B'
>>> 

Suggesting to align sqlite3.Blob indexing behaviour so it expects ints and returns ints.

@erlend-aasland erlend-aasland added the type-bug An unexpected behavior, bug, or error label Apr 28, 2022
erlend-aasland added a commit to erlend-aasland/cpython that referenced this issue Apr 28, 2022
- get index now returns an int
- set index now requires an int in range(0, 256)
@JelleZijlstra
Copy link
Member

Credit to @Akuli who brought this up in python/typeshed#7684 (comment)

@serhiy-storchaka
Copy link
Member

There is also a similar deviation in mmap.

@JelleZijlstra
Copy link
Member

We probably can't fix that though, since mmap has already been in the stdlib for a long time.

JelleZijlstra pushed a commit that referenced this issue Apr 30, 2022
- get index now returns an int
- set index now requires an int in range(0, 256)

Resolves #92019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-sqlite3 type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants