I wish to implement something like the following. There is a class foo which contains a list of infoo objects. I was thinking that in order to overload the __add__ operator I should
class foo(object):
def __init__(self, infoo_list):
self.args = infoo_list
def __add__(self, other):
if isinstance(other, type(self)):
newargs = self.args + other.args
return foo(newargs)
elif isinstance(other, infoo_type):
newargs = self.args + [other]
return foo(newargs)
class infoo (object):
def __init__(self):
pass
def __add__(self, other):
return foo([self, other])
infoo_type = type(infoo())
As you may see foo is a container of infoo objects. You may have an infoo object alone in the universe and operate on it. But, no matter what, if you have to manage more than one, the foo object comes into play.
Even though the user could instantiate an infoo object to play, the code is oriented towards letting the interface of foo handle whenever there are more than one infoo.
Is this good practice? Am I breaking some golden rule?