Skip to content

Commit 3f874bc

Browse files
docs: Update ShareableList documentation for fixed trailing null bug
The bug where ShareableList stripped trailing null bytes has been fixed in Python 3.15. Update documentation to: - Note the fix with versionchanged directive - Update doctest to show correct behavior (nulls preserved) - Clarify workaround is only needed for Python 3.14 and earlier - Reference both original issue #106939 and fix issue #145261 Fixes failing doctest in CI where expected output showed old buggy behavior instead of corrected behavior.
1 parent 34003c6 commit 3f874bc

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

Doc/library/multiprocessing.shared_memory.rst

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -313,26 +313,33 @@ finishes execution.
313313

314314
.. note::
315315

316-
A known issue exists for :class:`bytes` and :class:`str` values.
317-
If they end with ``\x00`` nul bytes or characters, those may be
316+
.. versionchanged:: 3.15
317+
Fixed a bug where :class:`bytes` and :class:`str` values ending with
318+
``\x00`` nul bytes or characters were silently stripped when fetching
319+
them by index. Trailing nulls are now preserved correctly.
320+
See :gh:`106939` and :gh:`145261`.
321+
322+
In Python 3.14 and earlier, a bug exists where :class:`bytes` and
323+
:class:`str` values ending with ``\x00`` nul bytes or characters may be
318324
*silently stripped* when fetching them by index from the
319-
:class:`!ShareableList`. This ``.rstrip(b'\x00')`` behavior is
320-
considered a bug and may go away in the future. See :gh:`106939`.
325+
:class:`!ShareableList`. This ``.rstrip(b'\x00')`` behavior has been
326+
fixed in Python 3.15.
321327

322-
For applications where rstripping of trailing nulls is a problem,
323-
work around it by always unconditionally appending an extra non-0
324-
byte to the end of such values when storing and unconditionally
325-
removing it when fetching:
328+
For applications that need to work with Python 3.14 and earlier where
329+
rstripping of trailing nulls is a problem, work around it by always
330+
unconditionally appending an extra non-0 byte to the end of such values
331+
when storing and unconditionally removing it when fetching:
326332

327333
.. doctest::
328334

329335
>>> from multiprocessing import shared_memory
330336
>>> nul_bug_demo = shared_memory.ShareableList(['?\x00', b'\x03\x02\x01\x00\x00\x00'])
331337
>>> nul_bug_demo[0]
332-
'?'
338+
'?\x00'
333339
>>> nul_bug_demo[1]
334-
b'\x03\x02\x01'
340+
b'\x03\x02\x01\x00\x00\x00'
335341
>>> nul_bug_demo.shm.unlink()
342+
>>> # Workaround for Python 3.14 and earlier (not needed in 3.15+):
336343
>>> padded = shared_memory.ShareableList(['?\x00\x07', b'\x03\x02\x01\x00\x00\x00\x07'])
337344
>>> padded[0][:-1]
338345
'?\x00'

0 commit comments

Comments
 (0)