Using the reference pointed to by Kevin you can do something like:
from multimethod import multimethod
class Person(object):
def __init__(self, myname):
self.name = myname
def __str__(self):
return self.name
def __repr__(self):
return self.__str__()
@multimethod(list, object)
def addPerson(l, p):
l = l +[p]
return l
@multimethod(list, str)
def addPerson(l, name):
p = Person(name)
l = l +[p]
return l
alist = []
alist = addPerson(alist, Person("foo"))
alist = addPerson(alist, "bar")
print(alist)
The result will be:
$ python test.py
[foo, bar]
(You need to install multimethod first.)