I would like to specialize / subclass the requests package to add some method with custom functionality.
I tried to do this:
# concrete_requests.py
import requestsclass concreteRequests(requests):def __init__(self):super(concreteRequests, self).__init__() self.session()def login(self):payload = {'user': 'foo', 'pass': 'bar'}self.get('loginUrl', headers=header, data=payload)# more login stuff...# my_class.py
class MyClass:def __init__():self.requests = concreteRequests()self.requests.login()
This way I could still benefit from self.requests
members + my concrete implementation. So I could do: self.requests.get(...)
or print(self.requests.post(...).status_code)
and so on.
I guess that this line super(concreteRequests, self).__init__()
can be stupidly useless since requests doesn't have any class declaration inside just imports...
So, the requests package can be subclassed/specialized through inheritance ?