-
-
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
multiprocessing.Value.value needs to be defined #10319
Comments
I've tripped over this recently myself, the two levels of indirection between So the choice kinda is, add about 30 overloads/complicated type unions to handle all the basic ctypes and their corresponding string literals correctly (but probably still have a lot of edge cases that are inferred wrong, due to inheritance) or just return To get around it you can do what I ended up doing and force cast it to import multiprocessing as mp
x = mp.Value('i', 0)
with x: # aquires lock
x.get_obj().value = 0 It's obviously a lot more verbose, but it will work without mypy complaining. (You probably should bind SynchronizedBase to the correct c_type though, so mypy can infer the return value of Another option would be to use So the following will be inferred correctly by mypy: import multiprocessing as mp
from ctypes import c_int
from multiprocessing.sharedctypes import synchronized
x = synchronized(mp.RawValue(c_int, 0))
reveal_type(x) # Revealed type is "multiprocessing.sharedctypes.Synchronized[builtins.int]"
There's also some caveats to using the property on |
The following sample code:
Produces this output when run:
But mypy complains:
Python version:
Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec 6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)] on win32
mypy version:
mypy==1.3.0
The text was updated successfully, but these errors were encountered: