Skip to content

[multiprocessing] Fix return types of Value and Array - #16485

Open
anistark wants to merge 1 commit into
python:mainfrom
anistark:fix-multiprocessing-value-types
Open

anistark wants to merge 1 commit into
python:mainfrom
anistark:fix-multiprocessing-value-types

Conversation

@anistark

@anistark anistark commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Closes #10319.

Make multiprocessing.Value/Array and their multiprocessing.sharedctypes counterparts match the runtime: they return the raw ctypes object (or ctypes.Array) for lock=False, Synchronized for simple C types and typecode strings, and SynchronizedBase for other ctypes such as structures. See Value/Array and synchronized().

Prepared with Claude Code.

The stubs did not match what CPython returns:

- With `lock=False`, `Value` and `Array` return the raw ctypes object.
  `BaseContext.Value` claimed `Synchronized[_CT]` instead of `_CT`, and
  both `Array` stubs returned something other than `ctypes.Array[_CT]`.
- `sharedctypes.Value` returned `SynchronizedBase` for simple C types
  and typecode strings, hiding the `value` attribute that the runtime
  `Synchronized` wrapper provides.
- `BaseContext.Value` returned `Synchronized[_CT]` for other ctypes
  such as structures. These are wrapped in a `SynchronizedBase`
  subclass that has no `value` attribute.

Make both modules match the runtime and each other.

Fixes python#10319
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

multiprocessing.Value.value needs to be defined

1 participant