- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.9k
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.Queueis documented as a class: https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Queue
- 
multiprocessing.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.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 Queueand 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.QueuetoQueue[T]to preserve type checking precision (this may not work on all type checkers).