Skip to content

Improve the error message for invalid typecodes in multiprocessing.{Array,Value} #133017

Closed

Description

@tomasr8

Feature or enhancement

Proposal:

More discussion: #132504 (comment)

This is the current message which is not very clear (it comes from ctypes.sizeof):

>>> from multiprocessing import Array
>>> Array('x', 1)
...
TypeError: this type has no size

I propose we change it to:

>>> from multiprocessing import Array
>>> Array('x', 1)
TypeError: bad typecode (must be a ctypes type or one of c, b, B, u, h, H, i, I, l, L, q, Q, f or d)

This is modeled after the error message in array.array which is more informative:

>>> array('x')
...
ValueError: bad typecode (must be b, B, u, w, h, H, i, I, l, L, q, Q, f or d)

(A ValueError seems like a more appropriate option for multiprocessing as well, but that'd be a breaking change)
Note that, multiprocessing.Array (and Value) does not support the 'w' typecode while array.array does.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

#132504 (comment)

Linked PRs

Activity

  1. added
    stdlib
    type-feature
    on Apr 26, 2025
  2. self-assigned this
    on Apr 26, 2025
  3. added a commit that references this issue on May 9, 2025
  4. added a commit that references this issue on Jul 12, 2025
  5. added a commit that references this issue on Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

stdlibtopic-multiprocessingtype-feature

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions