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
No, adding type annotations is not currently in the roadmap. Thanks for the pointer to multiprocessing from typeshed. I'll have to look into whether it's realistic to use that as a base as opposed to the stdlib multiprocessing.
Second vote for type hints. Type hints and mypy make Python programming for more robust since the linter will notice many (most of) issues that would otherwise be runtime errors. But I can image it would be quite an effort to add.
Reacted by metaist, Cecil Curry, Ivan, Qqwy / Marten and codethief
@chdominguez I believe in your second workaround there's a typo: Cast should be cast.
Either way, for some weird reason it doesn't seem to work in Pylance/Pyright, unfortunately: In expressions like mp.Process() go-to-definition in VSCode will work (well, it will take you to multiprocessing.Process instead of multiprocess.Process) but Pylance will still underline Process and, likewise, Pyright will complain on the command line:
foo.py:34:22 - error: "Process" is not a known attribute of module "multiprocess"
Meanwhile, your first workaround works without issues.
@zhou13 My apologies for the delay, the notification about your message must have gotten burried.
Do you still have issues using it?
My point was that your stubs would probably be better if they referenced multiprocess instead of multiprocessing. (You can probably just run a search & replace.) Otherwise, like in @chdominguez's workaround, type checkers will validate usages against multiprocessing[0], and go-to-definition (ctrl+click) for e.g. multiprocess.Process will take you to the source code of multiprocessing.Process. (At least that's what happens for me in VSCode with Pylance.)
[0]: Obviously, this is fine as long as the interfaces of multiprocess and multiprocessing are exactly the same.
Activity
mmckerns commentedon Dec 24, 2022
No, adding type annotations is not currently in the roadmap. Thanks for the pointer to
multiprocessingfromtypeshed. I'll have to look into whether it's realistic to use that as a base as opposed to the stdlibmultiprocessing.martinResearch commentedon Dec 30, 2022
To be sure there is no confusion: It seems to me that we cannot really oppose the code in here https://github.com/python/cpython/blob/main/Lib/multiprocessing with the code in here https://github.com/python/typeshed/tree/main/stdlib/multiprocessing. It seems that the first one contains the library implementation and does not have any type annotation while the second contains only the annotations and no implementation.
mmckerns commentedon Dec 30, 2022
👍 there's no confusion
Jylpah commentedon Jan 24, 2023
Second vote for type hints. Type hints and
mypymake Python programming for more robust since the linter will notice many (most of) issues that would otherwise be runtime errors. But I can image it would be quite an effort to add.mcrespoae commentedon May 30, 2024
Following up on this issue: Third vote for type hints.
chdominguez commentedon Jun 25, 2024
As a workaround, you can cast
multiprocessasmultiprocessingfor type annotations during development using the typing module:or
zhou13 commentedon Dec 1, 2024
I created a stubs package so it works for me: https://github.com/zhou13/multiprocess-stubs.
codethief commentedon Jul 3, 2025
@zhou13 Your stubs seem to import symbols from
multiprocessinginstead ofmultiprocess, though? E.g. inhttps://github.com/zhou13/multiprocess-stubs/blob/master/src/multiprocess/__init__.pyiyou importProcessfrommultiprocessing.contextinstead ofmultiprocess.context, meaning a type checker will validate usages ofmultiprocess.Process()againstmultiprocessing.context.Process, notmultiprocess.context.Process, whcih seems equivalent to @chdominguez's workaround.codethief commentedon Jul 3, 2025
@chdominguez I believe in your second workaround there's a typo:
Castshould becast.Either way, for some weird reason it doesn't seem to work in Pylance/Pyright, unfortunately: In expressions like
mp.Process()go-to-definition in VSCode will work (well, it will take you tomultiprocessing.Processinstead ofmultiprocess.Process) but Pylance will still underlineProcessand, likewise, Pyright will complain on the command line:Meanwhile, your first workaround works without issues.
zhou13 commentedon Jul 3, 2025
@codethief Yes, I simply copied files from https://github.com/python/typeshed/tree/main/stdlib/multiprocessing. Do you still have issues using it?
codethief commentedon Aug 12, 2025
@zhou13 My apologies for the delay, the notification about your message must have gotten burried.
My point was that your stubs would probably be better if they referenced
multiprocessinstead ofmultiprocessing. (You can probably just run a search & replace.) Otherwise, like in @chdominguez's workaround, type checkers will validate usages againstmultiprocessing[0], and go-to-definition (ctrl+click) for e.g.multiprocess.Processwill take you to the source code ofmultiprocessing.Process. (At least that's what happens for me in VSCode with Pylance.)[0]: Obviously, this is fine as long as the interfaces of
multiprocessandmultiprocessingare exactly the same.