You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Deriving from multiprocessing.get_context().Process #9860
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, the context variable is of type multiprocessing.context.DefaultContext, but that class appears to have a Process attribute:
Mypy's error message here is terrible, but it has a legitimate complaint: you're using an object annotated as a dynamic variable (Process) as a base class. That's problematic from a type-checking point of view.
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 :/
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.
Activity
AlexWaygood commentedon Mar 9, 2023
Mypy's error message here is terrible, but it has a legitimate complaint: you're using an object annotated as a dynamic variable (
Process) as a base class. That's problematic from a type-checking point of view.This is the same issue as:
selforcls[name-defined]mypy#14022I'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 :/
AlexWaygood commentedon Mar 9, 2023
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
Process: TypeAlias = Processwould help us at all, but it doesn't look like it: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
if TYPE_CHECKINGhack, something like the below:marcelm commentedon Mar 9, 2023
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.
AlexWaygood commentedon Mar 9, 2023
I gave a little bit more context here FYI, if that's helpful for understanding why mypy emits this error here!
pallets-eco/flask-sqlalchemy#1112 (comment)