Object not being recognized as duck-typed function

2 views
Skip to first unread message

Webb S.

unread,
Nov 14, 2010, 11:42:28 PM11/14/10
to cherrypy-devel
In summary, one needs to give __call__ a default parameter, otherwise
the object is not recognized as a function when it is called and
throws an error. I guess I can work around by using a default of
None, but I can't believe this is desired behavior. (If you add a
default and reload, then take it away and reload, it works OK -- even
weirder.) I will file a bug report shortly, but if anyone cares to
comment, I would be interested.

Using Python 7, a recent cherrypy.

Here is some that shows the problem:



import cherrypy

class Tree(object):
def index (self):
return "Hello World"
index.exposed = True
pass

class doesntwork(object):
def __init__(self, message='not working'):
self.x = "not working"
def __call__(self,xyz):
return xyz

class worksjustfine(object):
def __init__(self, message='works'):
self.x = "wtf works"
def __call__(self,xyz='this default parameter makes it work!!'):
return xyz


Tree.doesntwork = doesntwork()
Tree.doesntwork.exposed = True
Tree.worksjustfine = worksjustfine()
Tree.worksjustfine.exposed = True

if __name__ == '__main__':
tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf')
cherrypy.quickstart(Tree(), config=tutconf)
Reply all
Reply to author
Forward
0 new messages