代码大致如下,其中 parent class 是某个开源库类
# parent class
class A(object):
# ... bala bala ...
def test(self, url):
# ... bala bala ...
rsp = self.http.send(url=url)
rsp = json.loads(rsp.content)
self._session = self._session_type(rsp['a'], rsp['b'])
# subclass
class B(A):
def test(self, url):
# ... bala bala ...
rsp = self.http.send(url=url)
rsp = json.loads(rsp.content)
self._session = self._session_type(rsp['a'], rsp['b'])
self._xx = rsp['xx']
如果 A.test 有将 rsp 返回的话,那 subclass 就只需要
class B(A):
def test(self, url):
rsp = super(self.__class__, self).test(url)
self._xx = rsp['xx']
所以...是否有办法可以让 parent class 的 test 方法返回 rsp 呢?(排除修改 parent class 源码的方法)