Suppose I have a class A coming from a third-party library (FYI it is numpy.matrix). I want to expand its public interface with a wrapper class B.
class B(A):
def myMethod(self,arg):
return 'spam'
And also, I want to create B objects from A object. Since B will not hold any more attribute, I just really want to return the A object, with the B behavior:
class B(A):
def __new__(cls,a): # type(a)==A
return a.castTo(B) # pseudo-code
Is there a way to do it in python ?
Similarily, is there a way to cast B objects to A objects ?