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

Add aliases for 'function classes' to multiprocessing #5346

Merged
merged 2 commits into from
May 16, 2021

Conversation

srittau
Copy link
Collaborator

@srittau srittau commented May 5, 2021

Part of #4313

@github-actions
Copy link
Contributor

github-actions bot commented May 5, 2021

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@github-actions
Copy link
Contributor

github-actions bot commented May 5, 2021

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@Akuli
Copy link
Collaborator

Akuli commented May 6, 2021

I'm still not sure if we should do this. Even though lies in typeshed often result in problems, I think this is more of a "practicality beats purity" case, as being able to use multiprocessing.Event or multiprocessing.Queue as a type annotation has several advantages:

  • It is what users of typeshed expect. This is important. Even though they aren't types at runtime, that likely isn't a problem in practice. For example, isinstance(some_object, multiprocessing.Queue) errors every time, instead of silently doing the wrong thing. Also, isinstance checks like that are much less common than type annotations.
  • Not-what-you-would-expect things need documentation. A comment somewhere in typeshed's stub files does not suffice, and we don't really have a good place where the documentation would go.
  • Type checkers don't give a good error message for using a function as a type annotation. If you should use multiprocessing._Event as the type annotation instead of multiprocessing.Event, then the error message you get when using multiprocessing.Event should clearly say so. But it doesn't. It should either explain the situation or point to the documentation, wherever it would be.

@srittau
Copy link
Collaborator Author

srittau commented May 6, 2021

I'm strongly opposed to introducing more lies, especially in this case. For example, IDEs will report wrong signatures and the following will not report an error, but will fail at runtime:

from multiprocessing import Queue
class MyQueue(Queue): ...

There are probably more problems with lying, and often these problems are subtle and hard to spot for someone not knowing what's going on. On the other hand, using foo: Queue = Queue() is an immediate error and investigating that error will lead the use to the stubs and the correct solution.

@JelleZijlstra JelleZijlstra merged commit a7302dc into python:master May 16, 2021
@srittau srittau deleted the multiprocessing-aliases branch May 16, 2021 19:53
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

Successfully merging this pull request may close these issues.

None yet

3 participants