#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 is Queue[Any], so the change loses some typing precision, even if a user can figure out the correct type. Since multiprocessing.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 to Queue[T] to preserve type checking precision (this may not work on all type checkers).
#4289 changed
multiprocessing.Queuefrom 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.Queueis documented as a class: https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Queuemultiprocessing.queues.Queuecan 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.QueueisQueue[Any], so the change loses some typing precision, even if a user can figure out the correct type. Sincemultiprocessing.queues.Queueis 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.Queueas a type, without an obvious fix.The above considerations probably explain why
multiprocessing.Queueused 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:
Queueand other similar types (at least for now).multiprocessing.queues.Queue(etc.) in type annotations. However, if these are undocumented, maybe we shouldn't recommend these?multiprocessing.QueuetoQueue[T]to preserve type checking precision (this may not work on all type checkers).