-
-
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
Added initial rework of the concurrent.futures module #5646
Conversation
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.
(not a full review) just a couple scattered notes:
- It would be good to preserve facets of the existing stubs, e.g. _WorkItem being Generic
- Similarly, prefer inheriting methods from BaseExecutor over redefining them with the same type. That way shutdown will have the right signature for earlier versions of Python than 3.9 as well
- ThreadPoolExecutor uses queue, not multiprocessing.queues
Thank you for notes! I'm not very well-versed in using Generics and TypeVars so I'm not sure how/what to do with them - I tried fixing them up in a follow-up commit, but not sure what the naming conventions and standards are for them (the docs are kind of lacking and there aren't any in-depth tutorials out there) As for inheritance, how would I do that in the As for the queues, I fixed them in another commit. Thanks again for taking a look! |
This comment has been minimized.
This comment has been minimized.
I haven't looked at your code, but I'll try to explain when to use generics (and typevars). A simple example is a list: annotating something as Basically, a TypeVar is useful for a class that contains other values of arbitrary type, but they are always of the same type. If the wrapped value can have different types, then generics don't help. For example, Inheritance in For naming conventions, feel free to look at existing stubs and make pull requests that improve our CONTRIBUTING.md. Also, don't worry about it too much! We will point out if your naming isn't conventional enough. |
Awesome, I get it a bit better now. I'll keep working on it and hopefully have it set up. I've been going over the CONTRIBUTING.md file but I'll definitely keep checking it as I write more.
I'm not sure if this ends up being a limitation of |
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.
A few notes on things I have spotted, not a full review.
stdlib/concurrent/futures/_base.pyi
Outdated
_FUTURE_STATES: Sequence[str] | ||
_STATE_TO_DESCRIPTION_MAP: Mapping[str, str] |
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.
As these have concrete values (and are not supposed to be overwritten), we should use List
and Dict
, instead of the abstract classes.
_WI = TypeVar["_WI"] | ||
_RI = TypeVar["_RI"] | ||
_CI = TypeVar["_CI"] |
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.
Type vars use round parenthese: _WI = TypeVar("_WI")
.
import multiprocessing.connection as mpconn | ||
import multiprocessing.context as mpcont |
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.
Just use from abc import Whatever
, unless an import conflicts with a name in this module.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
Re-reviewed, fixed, and re-tested successfully
This comment has been minimized.
This comment has been minimized.
1 similar comment
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.
Thanks, remarks below.
Co-authored-by: Sebastian Rittau <[email protected]>
Co-authored-by: Sebastian Rittau <[email protected]>
This comment has been minimized.
This comment has been minimized.
2 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Maybe we should use my |
This comment has been minimized.
This comment has been minimized.
Seems that the It doesn't seem to be throwing errors at the definition of the |
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.
Reviewed and applied
Diff from mypy_primer, showing the effect of this PR on open source code: optuna (https://github.com/optuna/optuna.git)
+ optuna/study/_optimize.py:103: error: Incompatible types in assignment (expression has type "AbstractSet[Future[Any]]", variable has type "Set[Future[Any]]")
core (https://github.com/home-assistant/core.git)
+ homeassistant/util/executor.py:67: error: unused "type: ignore" comment
+ homeassistant/util/executor.py:92: error: unused "type: ignore" comment
SinbadCogs (https://github.com/mikeshardmind/SinbadCogs.git)
+ devtools/runner.py:26: error: unused "type: ignore" comment
|
Diff from mypy_primer, showing the effect of this PR on open source code: optuna (https://github.com/optuna/optuna.git)
+ optuna/study/_optimize.py:103: error: Incompatible types in assignment (expression has type "AbstractSet[Future[Any]]", variable has type "Set[Future[Any]]")
SinbadCogs (https://github.com/mikeshardmind/SinbadCogs.git)
+ devtools/runner.py:26: error: unused "type: ignore" comment
core (https://github.com/home-assistant/core.git)
+ homeassistant/util/executor.py:67: error: unused "type: ignore" comment
+ homeassistant/util/executor.py:92: error: unused "type: ignore" comment
|
Diff from mypy_primer, showing the effect of this PR on open source code: optuna (https://github.com/optuna/optuna.git)
+ optuna/study/_optimize.py:103: error: Incompatible types in assignment (expression has type "AbstractSet[Future[Any]]", variable has type "Set[Future[Any]]")
anyio (https://github.com/agronholm/anyio.git)
+ src/anyio/from_thread.py:390: error: Argument 1 to "wait" has incompatible type "Iterable[Future[Any]]"; expected "AbstractSet[Future[<nothing>]]"
SinbadCogs (https://github.com/mikeshardmind/SinbadCogs.git)
+ devtools/runner.py:26: error: unused "type: ignore" comment
core (https://github.com/home-assistant/core.git)
+ homeassistant/util/executor.py:67: error: unused "type: ignore" comment
+ homeassistant/util/executor.py:92: error: unused "type: ignore" comment
|
Diff from mypy_primer, showing the effect of this PR on open source code: core (https://github.com/home-assistant/core.git)
+ homeassistant/util/executor.py:67: error: unused "type: ignore" comment
+ homeassistant/util/executor.py:92: error: unused "type: ignore" comment
SinbadCogs (https://github.com/mikeshardmind/SinbadCogs.git)
+ devtools/runner.py:26: error: unused "type: ignore" comment
|
Diff from mypy_primer, showing the effect of this PR on open source code: optuna (https://github.com/optuna/optuna.git)
+ optuna/study/_optimize.py:103: error: Incompatible types in assignment (expression has type "AbstractSet[Future[Any]]", variable has type "Set[Future[Any]]")
core (https://github.com/home-assistant/core.git)
+ homeassistant/util/executor.py:67: error: unused "type: ignore" comment
+ homeassistant/util/executor.py:92: error: unused "type: ignore" comment
SinbadCogs (https://github.com/mikeshardmind/SinbadCogs.git)
+ devtools/runner.py:26: error: unused "type: ignore" comment
|
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.
The one primer hit seems like an easy and sensible fix. That more than balanced by three now unnecessary type ignores.
Added most of the missing sections present in the
concurrent.futures
module for theprocess.pyi
andthread.pyi
files, related to #4641.I'm sure there are plenty of edits needed for formatting reasons (like using generic types or TypeVars) so please let me know what should be added/fixed!