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: OptimizedUnicode obsolete in Py3k #58129

Closed
akheron opened this issue Feb 1, 2012 · 10 comments
Closed

sqlite3: OptimizedUnicode obsolete in Py3k #58129

akheron opened this issue Feb 1, 2012 · 10 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@akheron
Copy link
Member

akheron commented Feb 1, 2012

BPO 13921
Nosy @pitrou, @merwok, @akheron
Files
  • issue13921.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2012-02-09.19:11:08.057>
    created_at = <Date 2012-02-01.20:57:37.732>
    labels = ['type-bug', 'library']
    title = 'sqlite3: OptimizedUnicode obsolete in Py3k'
    updated_at = <Date 2012-02-09.19:13:15.233>
    user = 'https://github.com/akheron'

    bugs.python.org fields:

    activity = <Date 2012-02-09.19:13:15.233>
    actor = 'petri.lehtinen'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-02-09.19:11:08.057>
    closer = 'python-dev'
    components = ['Library (Lib)']
    creation = <Date 2012-02-01.20:57:37.732>
    creator = 'petri.lehtinen'
    dependencies = []
    files = ['24397']
    hgrepos = []
    issue_num = 13921
    keywords = ['patch']
    message_count = 10.0
    messages = ['152441', '152442', '152464', '152465', '152466', '152468', '152602', '152688', '152975', '152976']
    nosy_count = 5.0
    nosy_names = ['ghaering', 'pitrou', 'eric.araujo', 'python-dev', 'petri.lehtinen']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue13921'
    versions = ['Python 3.2', 'Python 3.3']

    @akheron
    Copy link
    Member Author

    akheron commented Feb 1, 2012

    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.

    @akheron akheron added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Feb 1, 2012
    @pitrou
    Copy link
    Member

    pitrou commented Feb 1, 2012

    +1 for removing, it makes no sense under Python 3.

    @akheron
    Copy link
    Member Author

    akheron commented Feb 2, 2012

    Attached a patch. It changes OptimizedUnicode to be an alias for PyUnicode_Type and adds a note to the documentation for porters from 2.x that it has no effect on py3k.

    The patch removes/refactors all OptimizedUnicode and allow_8bit_chars related obsolete code that had been left over from py3k transition. These removals/refactorizations have no operational effect, so the module still works the same way it has always worked in Py3k.

    Should OptimizedUnicode be deprecated, too? In this case, it cannot be aliased to str, and _pysqlite_fetch_one_row() needs to raise a DeprecationWarning if OptimizedUnicode is used.

    @pitrou
    Copy link
    Member

    pitrou commented Feb 2, 2012

    Should OptimizedUnicode be deprecated, too?

    I'd say just undocument it.

    @akheron
    Copy link
    Member Author

    akheron commented Feb 2, 2012

    > Should OptimizedUnicode be deprecated, too?

    I'd say just undocument it.

    Even remove the note from the patch?

    @pitrou
    Copy link
    Member

    pitrou commented Feb 2, 2012

    Le jeudi 02 février 2012 à 16:43 +0000, Petri Lehtinen a écrit :

    Petri Lehtinen <petri@digip.org> added the comment:

    > > Should OptimizedUnicode be deprecated, too?
    >
    > I'd say just undocument it.

    Even remove the note from the patch?

    Well, I guess keeping the note is fine.

    @merwok
    Copy link
    Member

    merwok commented Feb 4, 2012

    I’m not sure the doc note is useful, but didn’t code search to confirm it.

    Also, 3.2 may be out of bounds for this cleanup (I don’t know the rules for what can be committed in what branches these days).

    @merwok merwok changed the title sqlite3: OptimizedUnicode doesn't work in Py3k sqlite3: OptimizedUnicode obsolete in Py3k Feb 4, 2012
    @akheron
    Copy link
    Member Author

    akheron commented Feb 5, 2012

    Éric Araujo wrote:

    I’m not sure the doc note is useful, but didn’t code search to
    confirm it.

    Yeah. Perhaps it would be better as a comment in the code.

    Also, 3.2 may be out of bounds for this cleanup (I don’t know the
    rules for what can be committed in what branches these days).

    My intention was to apply it to 3.3 only.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 9, 2012

    New changeset 0fc10a33eb4c by Petri Lehtinen in branch 'default':
    Undocument and clean up sqlite3.OptimizedUnicode
    http://hg.python.org/cpython/rev/0fc10a33eb4c

    @python-dev python-dev mannequin closed this as completed Feb 9, 2012
    @akheron
    Copy link
    Member Author

    akheron commented Feb 9, 2012

    Committed the patch after moving the documentation note to a source code comment instead. Thanks for reviews.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants