On 4/8/07, Guido van Rossum <[EMAIL PROTECTED]> wrote: > On 4/8/07, Paul Pogonyshev <[EMAIL PROTECTED]> wrote: > > Guido van Rossum wrote: > > > What if someone passes a callable that doesn't have the expected > > > signature? > > Well, I don't know a way to catch such situations now, so removing > > callable() will not make it worse (even if you don't know about hasattr > > trick above.) > My point is that it's futile to use callable() -- even if it passes, > you have no assurance that you actually have a valid callback. So why > bother with it at all? It's counter to the spirit of Python. If > someone passes you a bad callback, they will see a traceback when you > call it. Then they fix their program. That's how it's supposed to > work.
But what if you need to do different things based on argument is callable or not? Take for example "Dependency Injection" recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413268 It uses callable to differentiate whether it needs to use object as singleton or to instantiate it on each request. I'm sure there might be other uses for callable when it's really useful. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com