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

Subclassing Callable #617

DaniGuardiola opened this Issue Feb 27, 2019 · 3 comments


None yet
3 participants
Copy link

DaniGuardiola commented Feb 27, 2019

I have a bunch of types defined like this:

t_wrapped_deferred_return = Dict[str, any]
t_deferred_return = Dict[str, any]
t_sync_return = Dict[str, str]
t_return = Union[t_sync_return, t_deferred_return]

class OperationCallable(Callable[[Stack, Union[bytes, None]], t_return]):
    type: str

Then I'm using a function typed with OperationCallable elsewhere, like this:


This is throwing a mypy (I assume, I'm using PyCharm) error:

'OperationCallable' object is not callable

Am I missing something? Is there a different way to go about this?



This comment has been minimized.

Copy link

gvanrossum commented Feb 27, 2019

You can't actually use Callable as a base class. If you don't get an error on that, you're probably not using mypy but just getting whatever errors PyCharm produces on its own (it has a sophisticated type inference engine, it just works different than mypy).

There is no bug here, please see our gitter channel for more help:

@gvanrossum gvanrossum closed this Feb 27, 2019


This comment has been minimized.

Copy link

ilevkivskyi commented Feb 27, 2019

This tracker is not about mypy. It is about runtime issues in the backport of typing to older versions of Python.

Anyway, this error is correct, because just by inheriting from Callable you don't make a class callable, you must implement the __call__() method. Also mypy shows Invalid base class for this code, see python/mypy#4031.


This comment has been minimized.

Copy link

DaniGuardiola commented Feb 27, 2019

Thanks @gvanrossum and @ilevkivskyi, I'll ask on Gitter and check the mypy issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.