You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
multiprocessing classes SimpleQueue and Queue don't support typing in 3.11.0 #99509
As reviewers noted in the linked PR, the linked PR only solves it for an undocumented way to import Queue. Also, even with the new import it's not a drop in replacement. I tested with 3.12beta 3.
multiprocessing.Queue() is the documented, public-API way of creating the class; however,
multiprocessing.Queue itself is not a type (it's a method), so can't be used in a type annotation
Could we special-case multiprocessing.Queue, perhaps by pretending in typeshed that it's a class rather than a method? Perhaps we could, but we like to avoid doing that kind of thing as much as possible. It's generally best for type checkers to be told the truth; lying to type checkers in typeshed about whether things are methods or classes can have unfortunate consequences. In any event, that conversation would probably need to take place on the https://github.com/python/typeshed/issues issue tracker rather than at CPython.
Could multiprocessing.Queue itself be changed so that it's an actual class rather than a method? Again, perhaps. I'm not a multiprocessing expert, though (just a typing expert), so I can't really comment on that one.
Reacted by YANG Qi, AndrewCleveland-Hearst, Shir Amir, Anton Yablokov, Jianan Wang and rysson
Activity
pythongh-99509: Add `__class_getitem__` to `multiprocessing.Qeueu`
gh-99509: Add `__class_getitem__` to `multiprocessing.queues.Queue` (#…
Merged main into regmachine branch (#50)
linguini1 commentedon Jun 15, 2023
I am using Python 3.11.4 and still get this error:
And using
SimpleQueue subscripting only works when imported using
from multiprocessing.queues import SimpleQueue.Starbuck5 commentedon Jul 10, 2023
I believe this should be re-opened.
As reviewers noted in the linked PR, the linked PR only solves it for an undocumented way to import Queue. Also, even with the new import it's not a drop in replacement. I tested with 3.12beta 3.
The new import yields an error.
To work around subscripting after this PR, you need to use the undocumented queue import and then provide this unknown context argument directly.
And of course the documented way of making a
Queuestill fails.hongwen000 commentedon Oct 1, 2023
@Starbuck5 Same issue
AlexWaygood commentedon Oct 1, 2023
To make both mypy and CPython happy, you can do something like this:
This accurately reflects the facts that:
multiprocessing.Queue()is the documented, public-API way of creating the class; however,multiprocessing.Queueitself is not a type (it's a method), so can't be used in a type annotationCould we special-case
multiprocessing.Queue, perhaps by pretending in typeshed that it's a class rather than a method? Perhaps we could, but we like to avoid doing that kind of thing as much as possible. It's generally best for type checkers to be told the truth; lying to type checkers in typeshed about whether things are methods or classes can have unfortunate consequences. In any event, that conversation would probably need to take place on the https://github.com/python/typeshed/issues issue tracker rather than at CPython.Could
multiprocessing.Queueitself be changed so that it's an actual class rather than a method? Again, perhaps. I'm not a multiprocessing expert, though (just a typing expert), so I can't really comment on that one.