Skip to content

Deprecate PyUnicode_AsUnicode(): emit a DeprecationWarning #66467

Closed

Description

@vstinner
BPO 22271
Nosy @loewis, @vstinner, @serhiy-storchaka

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 2017-06-28.01:28:55.053>
created_at = <Date 2014-08-25.01:41:16.478>
labels = []
title = 'Deprecate PyUnicode_AsUnicode(): emit a DeprecationWarning'
updated_at = <Date 2017-06-28.01:28:55.052>
user = 'https://github.com/vstinner'

bugs.python.org fields:

activity = <Date 2017-06-28.01:28:55.052>
actor = 'vstinner'
assignee = 'none'
closed = True
closed_date = <Date 2017-06-28.01:28:55.053>
closer = 'vstinner'
components = []
creation = <Date 2014-08-25.01:41:16.478>
creator = 'vstinner'
dependencies = []
files = []
hgrepos = []
issue_num = 22271
keywords = []
message_count = 5.0
messages = ['225860', '226245', '226296', '226297', '297115']
nosy_count = 3.0
nosy_names = ['loewis', 'vstinner', 'serhiy.storchaka']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue22271'
versions = ['Python 3.5']

Activity

  1. vstinner commented on Aug 25, 2014

    @vstinner
    MemberAuthor

    With the PEP-393 implemented in Python 3.3, PyUnicode_AsUnicode() and all similar functions have to convert the compact string to a heavy wchar_t* string (UCS-4 on Linux: 4 bytes per character, UTF-16 on Windows: 2 or 4 bytes per character) which is stored in the string. The heavy "Py_UNICODE*" storage is kept until the string is destroyed, which may only occur at Python exit.

    To reduce the memory footprint, it would be nice to promote the usage of the PEP-393 and start to emit a DeprecationWarning warning. The Py_UNICODE type and all related functions are already deprecated in the documentation.

    The deprecate PyUnicode_AsUnicode(), we should stop using it in Python itself. For example, PyUnicode_AsWideCharString() can be used to encode filenames on Windows, it doesn't store the encoded string in the Python object. See for example path_converter() in posixmodule.c.

  2. vstinner commented on Sep 1, 2014

    @vstinner
    MemberAuthor

    The deprecate PyUnicode_AsUnicode(), we should stop using it in Python itself.

    Here is the first step: issue bpo-22323, "rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString()" (to not call PyUnicode_AsUnicode() anymore).

  3. serhiy-storchaka commented on Sep 3, 2014

    @serhiy-storchaka
    Member

    It would be better to emit a warning only at compile time. End user of compiled extension can't do anything with a warning emitted at run time, only its author can avoid it.

  4. vstinner commented on Sep 3, 2014

    @vstinner
    MemberAuthor

    It would be better to emit a warning only at compile time. End user of compiled extension can't do anything with a warning emitted at run time, only its author can avoid it.

    DeprecatedWarning warnings are silent by default. So it will not annoy users.

  5. vstinner commented on Jun 28, 2017

    @vstinner
    MemberAuthor

    Sorry I lost track of this issue, I just close it.

    Note: Serhiy recently worked on wchar_t functions of PyUnicodeObject to detect embedded null characters, see for example bpo-30708.

  6. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions