Description
#4289 changed multiprocessing.Queue
from a class to a function. This matches the implementation, but this has some possibly unanticipated side effects, as discussed in python/mypy#9100. Here's a summary of the points raised in the linked PR:
-
multiprocessing.Queue
is documented as a class: https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Queue -
multiprocessing.queues.Queue
can be used in annotations, but it seems to be undocumented. For a user to annotate code using queues, they need to either read the stubs or the stdlib implementation, which is unfortunate. -
The return type of
multiprocessing.Queue
isQueue[Any]
, so the change loses some typing precision, even if a user can figure out the correct type. Sincemultiprocessing.queues.Queue
is not very discoverable (as it's undocumented), for many new users this may effectively remove the ability to type check queue items. -
The change breaks existing code that uses
multiprocessing.Queue
as a type, without an obvious fix.
The above considerations probably explain why multiprocessing.Queue
used to be defined as a class, even thought it's not quite true.
I'm not sure what's the best way forward. Here are some ideas:
- Revert the change to
Queue
and other similar types (at least for now). - Teach type checkers to suggest using
multiprocessing.queues.Queue
(etc.) in type annotations. However, if these are undocumented, maybe we shouldn't recommend these? - Change the return type of
multiprocessing.Queue
toQueue[T]
to preserve type checking precision (this may not work on all type checkers).