-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
abstract class shouldn't be considered Callable #12361
Comments
The built-in callable function returns true on the abstract class. I guess the typing error is not raised due to ABC appears to be callable but it's not callable as it can't be instantiated. |
I strongly disagree with this. AnyIO has a number of abstract classes where their |
Can you provide an example to show that this is a pattern worth supporting? If a Python API user calls a class, they expect to get an instance of that specific class, not an instance of a subclass. |
AnyIO is an async "meta-framework" that delegates actual I/O to underlying frameworks like asyncio or Trio. Therefore it has classes like |
I disagree with this. Having a separate factory method like |
That ship has sailed, and nobody has complained about this design change. It makes it much easier to shift from asyncio to AnyIO when these classes essentially work the same way in both libraries. I dislike that MyPy enforces certain design choices on its users, without them even being mandated by any PEP whatsoever. |
If you have a Otherwise, I think the philosophy is that types are meant to enforce the expected behaviour, and a I think it'd be fair, in this respect, to require an alternate notation to mark this kind of special behaviour. I'd also assume that requiring this special notation is the lesser evil; being able to assign an abstract class to a Callable will result in runtime failure. |
Python has, as long as I remember, allowed Therefore, if a class with a |
Yes, that sounds right. It's not about the class, but about the |
Bug Report
An abstract class fits the typing for
Callable
.To Reproduce
Expected Behavior
mypy should report a typing error if an abstract class is put where a
Callable
should goActual Behavior
mypy doesn't report any error if an abstract class is put where a
Callable
should goYour Environment
The text was updated successfully, but these errors were encountered: