Skip to content
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

ProcessPoolExecutor initializer 3.11 overloads return object? #11400

Open
davetapley opened this issue Feb 11, 2024 · 2 comments
Open

ProcessPoolExecutor initializer 3.11 overloads return object? #11400

davetapley opened this issue Feb 11, 2024 · 2 comments

Comments

@davetapley
Copy link

The docs say:

initializer is an optional callable that is called at the start of each worker process;

No mention of it returning anything.

And type is Callable[..., None] as expected:

class ProcessPoolExecutor(Executor):
_mp_context: BaseContext | None
_initializer: Callable[..., None] | None

But then for >=3.11 there's this overload:

if sys.version_info >= (3, 11):
@overload
def __init__(
self,
max_workers: int | None = None,
mp_context: BaseContext | None = None,
initializer: Callable[[], object] | None = None,


Seems to have come in on 8b3b6bf.
@AlexWaygood am I missing something? 🤔

@hauntsaninja
Copy link
Collaborator

We should update the instance variable. Every Callable[..., None] is a Callable[[], object]. ProcessPoolExecutor just ignores whatever is returned, so it's valid to pass something into it that happens to return a value. Typeshed typically prefers false negatives over false positives.

See also the discussion in PyCQA/flake8-pyi#237 (comment)

@davetapley
Copy link
Author

Oh, TIL isinstance(None, object), I guess that should have been obvious 🤪

We should update the instance variable.

I'm not sure what variable you mean? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants