Skip to content

array: Add 'w' type and deprecate 'u' type. #80480

Description

@methane
BPO 36299
Nosy @terryjreedy, @ncoghlan, @methane, @skrah, @serhiy-storchaka
PRs
  • bpo-36299: array('u') uses Py_UCS4 instead of Py_UNICODE  #12497
  • 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 = None
    created_at = <Date 2019-03-15.05:50:02.657>
    labels = ['3.8', 'library']
    title = "array: Deprecate 'u' type in array module"
    updated_at = <Date 2020-04-23.00:47:43.731>
    user = 'https://github.com/methane'

    bugs.python.org fields:

    activity = <Date 2020-04-23.00:47:43.731>
    actor = 'methane'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2019-03-15.05:50:02.657>
    creator = 'methane'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36299
    keywords = ['patch']
    message_count = 12.0
    messages = ['337967', '338031', '338595', '338598', '338607', '338608', '338609', '338610', '338611', '367000', '367044', '367065']
    nosy_count = 5.0
    nosy_names = ['terry.reedy', 'ncoghlan', 'methane', 'skrah', 'serhiy.storchaka']
    pr_nums = ['12497']
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue36299'
    versions = ['Python 3.8']

    Linked PRs

    Activity

    methane commented on Mar 15, 2019

    @methane
    MemberAuthor

    The doc says:

    'u' will be removed together with the rest of the Py_UNICODE API.
    Deprecated since version 3.3, will be removed in version 4.0.
    https://docs.python.org/3/library/array.html

    But DeprecationWarning is not raised yet. Let's raise it.

    • 3.8 -- PendingDeprecationWarning
    • 3.9 -- DeprecationWarning
    • 4.0 or 3.10 -- Remove it.
    added
    stdlibStandard Library Python modules in the Lib/ directory
    on Mar 15, 2019

    terryjreedy commented on Mar 15, 2019

    @terryjreedy
    Member

    '4.0' is a stand-in for 'sometime after 2.7.final', scheduled for Jan 2020. A Pending... for 3.8.0, scheduled for Oct 2019, seems reasonable to me. Perhaps we should have a pydev discussion for the general issue of post 2.7 removals of already deprecated items.

    methane commented on Mar 22, 2019

    @methane
    MemberAuthor

    https://mail.python.org/pipermail/python-dev/2019-March/156807.html

    We may able to convert 'u' to wchar_t to int32_t and un-deprecate it.

    methane commented on Mar 22, 2019

    @methane
    MemberAuthor

    I found converting Py_UNICODE to Py_UCS4 wad happened, and reverted.
    ref: https://bugs.python.org/issue13072

    changed the title [-]Deprecate 'u' type in array module[/-] [+]array: Deprecate 'u' type in array module[/+] on Mar 22, 2019

    skrah commented on Mar 22, 2019

    skrahmannequin
    Mannequin

    I think the problem is still whether to use 'u' == UCS2 and 'w' == UCS4 like in PEP-3118.

    For the project I'm currently working on I'd need these for buffer exports:

    >>> from xnd import *
    >>> x = xnd(["abc", "xyz"], dtype="fixed_string(10, 'utf16')")
    >>> y = xnd(["abc", "xyz"], dtype="fixed_string(10, 'utf32')")
    >>> 
    >>> memoryview(x)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: type is not supported by the buffer protocol

    The use case is not an array that represents a single utf16 string, but
    an array *of* fixed strings with different encodings.

    So x would be exported with format 'u' and y with format 'w'.

    skrah commented on Mar 22, 2019

    skrahmannequin
    Mannequin

    Just to demonstrate what the format would look like, this is working
    for an array of fixed bytes:

    >>> x = xnd([b"123", b"23456"], dtype="fixed_bytes(size=10)")
    >>> memoryview(x).format
    '10s'

    So the formats in the previous message would be '10u' and '10w'.

    serhiy-storchaka commented on Mar 22, 2019

    @serhiy-storchaka
    Member

    array('u') is not tied with the legacy Unicode C API. It is possible to use the modern wchar_t based Unicode C API for it. See bpo-36346.

    There are benefits from getting rid of the legacy Unicode C API, but not from array('u').

    skrah commented on Mar 22, 2019

    skrahmannequin
    Mannequin

    array() uses struct module characters except for 'u'. PEP-3118 was
    supposed to be implemented in the struct module.

    If array() continues to use 'u', the only sensible thing would be
    to remove (or rename) 'a', 'u' and 'w' from PEP-3118.

    skrah commented on Mar 22, 2019

    skrahmannequin
    Mannequin

    The funny thing is that array() already knows this:

    >>> import array
    >>> a = array.array("u", "123")
    >>> memoryview(a).format
    'w'

    methane commented on Apr 22, 2020

    @methane
    MemberAuthor

    I closed #56706 (Py_UNICODE -> Py_UCS4).
    I created #63852 (Py_UNICODE -> wchar_t) instead.

    terryjreedy commented on Apr 22, 2020

    @terryjreedy
    Member

    Should this issue be closed, possibly as superseded by bpo-36346, the issue for the new PR-19653?

    methane commented on Apr 23, 2020

    @methane
    MemberAuthor

    While array('u') doesn't use deprecated API with #63852, I still don't like 'u' because:

    • I don't have any reason to use platform dependant wchar_t. 1
    • It is not consistent with PEP-3118.

    How about this plan?

    • Add 'w' for Py_UCS4.
    • Deprecate 'u', and remove it in the future.

    20 remaining items

    encukou commented on May 9, 2023

    @encukou
    Member

    How about:

    • Add 'w' for Py_UCS4.
    • Wait until all Python versions that don't have w reach end of life
    • Deprecate 'u', and remove it in the future.

    Is there a reason to rush this?

    methane commented on May 10, 2023

    @methane
    MemberAuthor

    array('u') will cause bugs and almost no valid use case for it.
    So waiting deprecation 5+ years seems too slow.

    On the other hand, I don't hurry about removing it.
    I can wait 3+ releases instead of minimum 2 releases.

    My plan is:

    • Add 'w' and deprecate 'u' in Python 3.13
    • Remove 'u' in Python 3.16+ (Postpone removal if some users still use 'u').
    changed the title [-]array: Deprecate 'u' type in array module[/-] [+]array: Add 'w' type and deprecate 'u' type.[/+] on May 10, 2023
    added a commit that references this issue on Jun 4, 2023

    vstinner commented on Jun 6, 2023

    @vstinner
    Member

    @methane added array.array('w') format to Python 3.13.

    @methane: Would you mind to also document the addition with versionchanged in https://docs.python.org/dev/library/array.html ? Currently, it's only documented at: https://docs.python.org/dev/whatsnew/3.13.html#array

    vstinner commented on Jun 6, 2023

    @vstinner
    Member

    I dislike the fact that array.array('u') is only deprecated in the doc. I would prefer to either emit a DeprecationWarning at runtime, or remove the deprecation. See also issue #105373. I'm fine with really deprecating it if someone wants to submit a PR (@methane ?).

    hugovk commented on Jun 6, 2023

    @hugovk
    Member

    @vstinner PR already open at #95760 :)

    added a commit that references this issue on Jun 11, 2023

    hugovk commented on Jun 11, 2023

    @hugovk
    Member

    array('u') will cause bugs and almost no valid use case for it. So waiting deprecation 5+ years seems too slow.

    On the other hand, I don't hurry about removing it. I can wait 3+ releases instead of minimum 2 releases.

    My plan is:

    • Add 'w' and deprecate 'u' in Python 3.13

    Done in #105242 and #95760.

    • Remove 'u' in Python 3.16+ (Postpone removal if some users still use 'u').

    Let's close this issue and come back to this in four years.

    added a commit that references this issue on May 8, 2026
    added a commit that references this issue on Jun 1, 2026

    vstinner commented on Jun 1, 2026

    @vstinner
    Member

    The array u type has been removed by the PR gh-149535.

    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

      3.13only security fixesextension-modulesC modules in the Modules dirtype-featureA feature request or enhancement

      Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions