Skip to content

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

Closed
@tomasr8

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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions