python - Overwrite a module type definition -


say using 3rd party api used requests module. like:

import requests  class thirdpartyapi(object):     '''     pretend api     '''     def __init__(self):         self._session = requests.session() 

and wanted said api use futuressession form requets-futures module out editing api source code

would have subclass thirdpartyapi so?

from requests_futures.sessions import futuressession  class subapi(thirdpartyapi):     '''     dependency inject futuresrequets session     '''     def __init__(self):         super().__init__()         self._session = futuressession() 

this doesn't seem best way. in above example _session gets written twice though want object assigned second time.

how dealt with? or best way it?

p.s: i'm aware tip of ice-berg implementing async-requsts third party api. responses become future objects. (one step @ tine)

it not best way performance point of view, since create unnecessary object. given constraint of not modifying base object, possible way. can't use "thirdpartyapi" without calling constructor.

it's not uncommon in large oo libraries sort of thing: pyqt in many cases, replacing 1 component in complex class customized behavior.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -