-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Base concurrent.futures.Executor on ContextManager #1711
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
Merged
JelleZijlstra
merged 5 commits into
python:master
from
joshstaiger:executor_context_manager
Nov 4, 2017
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
99cc86c
Base concurrent.futures.Executor on ContextManager
joshstaiger 260c1ba
Fix flake8 complaint.
joshstaiger cacaa2c
Revert "Fix flake8 complaint."
joshstaiger 89ec503
Revert "Base concurrent.futures.Executor on ContextManager"
joshstaiger 0ccc3f0
Make Executor.__enter__ self and return types match.
joshstaiger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
from typing import Optional, Any | ||
|
||
import sys | ||
|
||
from ._base import Future, Executor | ||
|
||
EXTRA_QUEUED_CALLS = ... # type: Any | ||
|
||
class BrokenProcessPool(RuntimeError): ... | ||
|
||
class ProcessPoolExecutor(Executor): | ||
def __init__(self, max_workers: Optional[int] = ...) -> None: ... | ||
if sys.version_info >= (3, 6): | ||
class ProcessPoolExecutor(Executor[ProcessPoolExecutor]): | ||
def __init__(self, max_workers: Optional[int] = ...) -> None: ... | ||
|
||
else: | ||
class ProcessPoolExecutor(Executor): | ||
def __init__(self, max_workers: Optional[int] = ...) -> None: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why can't you achieve what you want with the simpler solution of typing
__enter__
asdef __enter__(self: _T) -> _T: ...
, where_T
is a TypeVar bound to Executor? That would make the rest of this PR unnecessary and remove the version_info checks.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.
That would work, too.
I didn't do it that way because of the note here about generic selfs being experimental and not fully implemented.
But if you think that's the way forward I can rework it like that.
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.
But self is not generic here, is it? Executor itself is not a generic class.
Uh oh!
There was an error while loading. Please reload this page.
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 just meant "generic self" to mean that
self
has a TypeVar type (which I believe is what the note is describing).According to the note, I don't think it matters if the class (Executor) that gets bound to the TypeVar is itself a 'generic class'.
See the example, none of the
Shape
,Circle
, orSquare
are generic classes either.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.
My understanding is that self-types are fairly stable for non-generic classes (like the ones we're using here). The troubles arise when the class we're using a self type for is itself generic: see python/mypy#2354, python/mypy#3363, python/mypy#3631.
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.
In any case, self types are already widely used in typeshed for non-generic classes (grep finds about 130 usages). I'm confident that using them here too is safe.
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.
Okay, then! I'll rework this that way when I get a moment.