[Python-3000] callable()

Calvin Spealman ironfroggy at gmail.com
Mon Jul 17 20:18:18 CEST 2006


On 7/17/06, Josiah Carlson <jcarlson at uci.edu> wrote:
>
>
> "Alex Martelli" <aleaxit at gmail.com> wrote:
> >
> > On 7/17/06, Andrew Koenig <ark at acm.org> wrote:
> > > I note in PEP 3000 the proposal to remove callable(), with the comment
> "just
> > > call the object and catch the exception."
> > >
> > > I think that's a bad idea, because it takes away the ability to
> separate the
> > > callability test from the first call.  As a simple example, suppose
> you're
> > > writing a function that you expect to be given a function as one of
> its
> > > arguments:
> > >
> > >         def foo(bar, fun):
> > >                 assert callable(fun)
> > >                 # ...
> > >
> > > It might be that foo doesn't actually call fun until much later.
> > > Nevertheless, from a testing viewpoint, it would be better to detect
> the
> > > error immediately of passing something that can't be called.
> > >
> > > If you didn't have callable, how would you write this example?
> >
> > I might equivalently hasattr(type(fun), '__call__') [[net of oldstyle
> > classes, which won't be around in py3k anyway:-)]] and it would be
> > just as feeble -- essentially because when the time comes to CALL fun,
> > it will be called with specific signature[s], not "in a void".
>
> I believe that callable as it stands is useful for what it was intended
> to do; tell you if something is callable.  Whether or not a function is
> callable with a specific set of arguments as you suggest, would be
> useful, but not necessary in the cases that Andrew and others have been
> talking about.
>
> Also note that specifying and/or verifying call signatures is its own
> PEP.  I personally believe that callable should stay as-is, and if
> signature verification is going to be done, it should probably have its
> own builtin (as code that was using callable(foo) before could break
> with changed semantics, and such breakage, I believe, would be
> gratuitous).
>
> - Josiah


I like the idea of being able to ask callable about specific signitures. I
don't think it needs to be a seperate function, but you would need a way to
specify "is this callable with an unknown number of arguments?" and the
signiture of callable itself in this context would grow ambiguous without
well thought out arguments. Still, it would seem clunky to have seperate
functions to deal with it.

Then again, this could easily get out of hand and become interface
discussions all over again.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20060717/08c834c6/attachment.html 


More information about the Python-3000 mailing list