Object not being recognized as duck-typed function

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Object not being recognized as duck-typed function

Webb Sprague
 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

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)

You received this message because you are subscribed to the Google Groups "cherrypy-devel" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/cherrypy-devel?hl=en.