-
-
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
add annotation for multiprocessing.{Value,Array} with special c-types #11833
Conversation
stdlib/multiprocessing/context.pyi
Outdated
def Value(self, typecode_or_type: _CT, *args: Any, lock: Literal[False]) -> Synchronized[_CT]: ... | ||
@overload | ||
def Value(self, typecode_or_type: _CT, *args: Any, lock: Literal[True] | _LockLike = True) -> Synchronized[_CT]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You removed the type
"wrapper" here, while Array
still has it, was this intentional?
Also, could you add some test cases to test_cases/stdlib
? I think the multiprocessing stubs are sufficiently complex to warrant some.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was intentional and a misstake, which is why i re-added them now. I agree with test-cases, let's see what I can come up with.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…hronizedArray is not ready yet
This comment has been minimized.
This comment has been minimized.
What I could not get working: from multiprocessing import Array
from ctypes import c_float
a = Array(c_float, 2)
a[:] = [1.2, 4.1] # Incompatible types: expect c_float, found float Sadly, adding a new overload for this like it is done with |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to add the examples from your initial comment to the tests, see below.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
This PR adds support for
multiprocessing.Value
with standard c-types like c_float. Before this PR, Code likelead to
incompatible types in assignment
.Also this PR resolves a Problem addressed in #4266 where
lead to
SynchronizedArray[c_char] has no attribute value
, altrough documentation states that such arrays have araw
and avalue
field.Happy for your comments, lets see what I missed :)