-
-
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
Improve multiprocessing stubs #4266
Comments
I removed the good-first-issue label since some of these are fairly complicated to fix "right", see discussion in #4282 However, there are likely some easy fixes in here as well that do make good first issues! I'd recommend taking a look at any of the ones complaining about missing or differing arguments :-) |
With respect to
you get a mypy error, because Not sure if that means the typing in typeshed has to fix that, or if it is a documentation bug on the python side. |
typeshed tries to follow the implementation, not the documentation. In this case the documentation is at least misleading. |
So where do we report the documentation issue? |
See the conversation on #4313 Technically you could report this to bugs.python.org, but Python core devs are already aware of this. See https://bugs.python.org/issue19895 for example. |
@Akuli thanks for the pointers. We can work around it by doing
|
Maybe re-exporting the "proper" classes from |
Currently typeshed just says that But for some reason, |
We should not change those if they are already correct, and we should work towards fixing |
Is it possible to type a |
There isn't a great way; how best to type it depends on how exactly you're using it. Also willing to bet that the stubs could be improved (e.g. looks like the Is the code you're working on open source? That would help us, e.g. we could add it to https://github.com/hauntsaninja/mypy_primer |
I'm not doing anything too special with it, here's a simple example that I don't know how to properly type (as written mypy will complain):
Although in my actual code I'm using |
See discussion here: python#4266 (comment)
The precise type is probably I also made the change I suggested in #8330, which means you'll get a much more precise return type. Right now in your snippet, counter just ends up as Any. |
See discussion here: #4266 (comment) Co-authored-by: hauntsaninja <>
I think I found a blind spot? I upgraded mypy recently and now I get the following: import ctypes
from multiprocessing import Array
a = Array(ctypes.c_char, 32)
with a.get_lock():
print(a.value)
Where the docs explicitly say "that an array of ctypes.c_char has value and raw attributes which allow one to use it to store and retrieve strings." (https://docs.python.org/3/library/multiprocessing.html?highlight=array#multiprocessing.Array) |
For @madig s problem it looks like The same seems to be true in https://github.com/python/typeshed/blob/main/stdlib/multiprocessing/sharedctypes.pyi#L66, so that a = Value(ctypes.c_float, 0.0)
a.value = 1.0 # error: Incompatible types in assignment (expression has type "float", variable has type "c_float") [assignment] I think both should be quite easy to fix, but the overloads of |
See #10319, I think that is the same issue |
stubtest finds a number of issues with the existing multiprocessing stubs. PRs that work toward fixing these (if they need fixing) are welcome, even if they're small!
The text was updated successfully, but these errors were encountered: