python monkey patch
python - What is monkey patching? - Stack Overflow
Q: Is that something like methods/operators overloading or delegating?
A: NO, It's simply the dynamic replacement of attributes at runtime.
methods are just attributes of the class, you can do this as much as you like
実は、以下をみてて、monkey patch?となった。まだ、自分は知識も考えも足りない。
GoogleCloudPlatform/httplib2shim: urllib3 sanity for httplib2 users #shim
__init__.py#L91
code: except.py
setattr(httplib2, '_HttpOriginal', httplib2.Http)
httplib2.Http = Http #Httpは別途 class Http(httplib2.Http で作成(定義) したもの
元のmethodは、
https://github.com/httplib2/httplib2/blob/8b65b523359f0da7e91e130e4877f941cf4511d5/python3/httplib2/__init__.py#L1365
これで、根っこのruntimeレベルで差し替えに成功してる。たぶん。
参考:
setattr : Built-in Functions — Python 3.7.1 documentation
setattr(object, name, value)
#python