When to use __call__


request.get(url, auth: AuthBase=obj, **kwargs)
accepts a obj: requests.auth.AuthBase
to attach a user’s credentials required for a custom authentication flow.
It mutate's the request
object to generate an “Authorization” Header using the context(content) of the request itself. It uses this hook before making the network calling obj(request)
Your class needs to be a callable which is done by implementing __call__(self, *args)
. This can be used as a general hook to support esoteric use cases based on type
of the args your class is called with.
References
Subscribe to my newsletter
Read articles from Danny Crasto directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Danny Crasto
Danny Crasto
I am developer/code-reviewer/debugger/bug-fixer/architect/teacher/builder from dubai, uae