Repository navigation
array: Add 'w' type and deprecate 'u' type. #80480
Description
Activity
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.htmlBut DeprecationWarning is not raised yet. Let's raise it.
- 3.8 -- PendingDeprecationWarning
- 3.9 -- DeprecationWarning
- 4.0 or 3.10 -- Remove it.
- added3.8 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Mar 15, 2019 '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.
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.
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 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'.
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'.
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').
The funny thing is that array() already knows this:
>>> import array >>> a = array.array("u", "123") >>> memoryview(a).format 'w'
- Reacted by Alejandro R. Sedeño and C.A.M. Gerlach
20 remaining items
How about:
- Add
'w'for Py_UCS4. - Wait until all Python versions that don't have
wreach end of life - Deprecate
'u', and remove it in the future.
Is there a reason to rush this?
- Add
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 @methane added
array.array('w')format to Python 3.13.@methane: Would you mind to also document the addition with
versionchangedin https://docs.python.org/dev/library/array.html ? Currently, it's only documented at: https://docs.python.org/dev/whatsnew/3.13.html#array- added a commit that references this issue
on Jun 11, 2023 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').
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 The
arrayutype has been removed by the PR gh-149535.- moved this to Done in Struct, memoryview and array issues 🏗️
on Jul 13, 2026
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
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:
bugs.python.org fields:
Linked PRs