-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Deriving from multiprocessing.get_context().Process #9860
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
Comments
Mypy's error message here is terrible, but it has a legitimate complaint: you're using an object annotated as a dynamic variable ( This is the same issue as:
I'll check later to see if there's anything we can do to improve things, but I believe the stubs are probably correct here, in which case there's probably not much we can do here :/ |
Yes, there's nothing typeshed can do here to fix the error mypy emits on your current code :/ I wondered if changing the annotation here to typeshed/stdlib/multiprocessing/context.pyi Line 150 in a47dd76
The mypy error message is terrible (and the error itself is probably a pain to work around), but those are issues for mypy, not typeshed. I guess my best suggestion is to do an import multiprocessing
import multiprocessing.context
import typing
context = multiprocessing.get_context()
if typing.TYPE_CHECKING:
class MyProcess(multiprocessing.context.Process):
pass
else:
class MyProcess(context.Process):
pass |
Thanks! I understand now where the error message comes from. I’ll add a comment to the linked MyPy issue. Naively, this appears to be something that should work (considering this is code that works and that is even in the stdlib). Thanks also for the workaround; I would not have come up with it myself so quickly. |
I gave a little bit more context here FYI, if that's helpful for understanding why mypy emits this error here! |
This code:
fails to typecheck with the message
error: Name "context.Process" is not defined [name-defined]
.I tried to see whether I could contribute a PR, but have to admit I don’t even understand the error message. According to
reveal_type
, thecontext
variable is of typemultiprocessing.context.DefaultContext
, but that class appears to have aProcess
attribute:typeshed/stdlib/multiprocessing/context.pyi
Lines 149 to 150 in a47dd76
The text was updated successfully, but these errors were encountered: