-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recent multiprocessing.Queue change breaks existing annotations and reduces typing precision #4313
Comments
Making
But these problems feel less severe than the problems that @JukkaL points out with the current stubs. cc @vishalkuo and @hauntsaninja who were involved in the previous PR. |
The ultimate goal should be to have the stubs match the implementation. @JelleZijlstra points out some pitfalls otherwise that a type checker could help catch. As a pragmatic step for now I think Jelle's solution is ok, though. We could also add another stubs-only alias (like The "clever" implementation of multiprocessing has been a source of constant trouble. |
Partial revert of python#4289. Fixes python#4313
The combination of (Note all the changes from #4282 are intact since Array/Value aren't documented as classes. But they're also a little tricky since they return ctypes objects. If people feel the relevant parts of those changes should also be rolled back, this would be the place to discuss that) |
Hey all, thanks for flagging this and reverting it. It looks like #4314 reverts my bad change, but let me know if there's anything else you'll need me to resolve around this. Sorry for all the churn, I tried getting started on this to dip my toes a little deeper into the typed python world but it seems like the |
It's all good, |
Partial revert of python#4289. Fixes python#4313
#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.Queuemultiprocessing.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:
Queue
and 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.Queue
toQueue[T]
to preserve type checking precision (this may not work on all type checkers).The text was updated successfully, but these errors were encountered: