[New-bugs-announce] [issue13921] sqlite3: OptimizedUnicode doesn't work in Py3k
Petri Lehtinen
report at bugs.python.org
Wed Feb 1 21:57:38 CET 2012
New submission from Petri Lehtinen <petri at digip.org>:
Connection.text_factory can be used to control what objects are
returned for the TEXT data type. An excerpt from the docs:
For efficiency reasons, there’s also a way to return str
objects only for non-ASCII data, and bytes otherwise. To
activate it, set this attribute to sqlite3.OptimizedUnicode.
However, it always returns Unicode strings now. There's even a
test for this feature which is obviously wrong:
def CheckOptimizedUnicode(self):
self.con.text_factory = sqlite.OptimizedUnicode
austria = "Österreich"
germany = "Deutchland"
a_row = self.con.execute("select ?", (austria,)).fetchone()
d_row = self.con.execute("select ?", (germany,)).fetchone()
self.assertTrue(type(a_row[0]) == str, "type of non-ASCII row must be str")
self.assertTrue(type(d_row[0]) == str, "type of ASCII-only row must be str")
It checks for str in both cases even though it should test for
bytes in the latter case.
---
The user can get bytes if he wants to by saying so explicitly.
Having the library mix bytes and unicode by itself makes it
harder for the user. Furthermore, I don't really buy
the "efficiency" reason here, so I'd vote for removing the whole
OptimizeUnicode thing. It has never worked for Py3k so it would
be safe.
----------
components: Library (Lib)
messages: 152441
nosy: petri.lehtinen, pitrou
priority: normal
severity: normal
status: open
title: sqlite3: OptimizedUnicode doesn't work in Py3k
type: behavior
versions: Python 3.2, Python 3.3
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13921>
_______________________________________
More information about the New-bugs-announce
mailing list