Re: __call__ considered harmful or indispensable?

2007-08-03 Thread Skip Montanaro
Terry Reedy udel.edu> writes: > > The bug went something like this: > > > > obj = some.default_class > > ... > > if some_other_rare_condition_met: > > ... several lines ... > > obj = some.other_class() > > Should that have been some.other_class (without the ()s?). Ei

Re: __call__ considered harmful or indispensable?

2007-08-03 Thread Terry Reedy
Skip Montanaro a écrit : >>> In this case there was a bug. Depending on inputs, sometimes obj >>> initialized to a class, sometimes an instance of that class. (I fixed >>> that too while I was at it.) The problem was that the use of __call__ >>> obscured the underlying bug by making the instanc

Re: __call__ considered harmful or indispensable?

2007-08-03 Thread Duncan Booth
[EMAIL PROTECTED] wrote: > In this particular case it was clearly unnecessary and just obfuscated > the code. I'm wondering, are there some general cases where __call__ > methods of a user-defined class are simply indispensable? I don't know that you couldn't live without __call__, but it would

Re: __call__ considered harmful or indispensable?

2007-08-03 Thread Bruno Desthuilliers
Skip Montanaro a écrit : >>> In this case there was a bug. Depending on inputs, sometimes obj >>> initialized to a class, sometimes an instance of that class. (I fixed >>> that too while I was at it.) The problem was that the use of __call__ >>> obscured the underlying bug by making the instance

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Skip Montanaro
> > In this case there was a bug. Depending on inputs, sometimes obj > > initialized to a class, sometimes an instance of that class. (I fixed > > that too while I was at it.) The problem was that the use of __call__ > > obscured the underlying bug by making the instance as well as the class > >

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Carl Banks
On Aug 2, 2:30 pm, [EMAIL PROTECTED] wrote: > I'm wondering, are there some general cases where __call__ methods of > a user-defined class are simply indispensable? Indispensable's a strong word, but one thing that entails calling syntax, and can't (reasonably) be done with closures is to override

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Carl Banks
On Aug 2, 4:27 pm, Paul Rubin wrote: > [EMAIL PROTECTED] writes: > > In this particular case it was clearly unnecessary and just obfuscated the > > code. I'm wondering, are there some general cases where __call__ methods of > > a user-defined class are simply indispensab

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread James Stroud
James Stroud wrote: > import functools > class enclosable(object): > def __init__(self, func): > self.func = func > def __call__(self, *args, **kwargs): > return functools.partial(self.func, *args, **kwargs) > > For example: > > @enclosable > def do_something_with(a, b): > [etc] O

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread James Stroud
[EMAIL PROTECTED] wrote: > I don't personally use __call__ methods in my classes, but I have > encountered it every now and then here at work in code written by other > people. The other day I replaced __call__ with a more obvious method name, > so now instead of executing > > obj(foo, bar, b

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Paul Boddie
Bruno Desthuilliers wrote: > > Most of what you can do with a callable instance can be done with > closures (and is usually done so in FPLs), but given Python's OO nature, > it's sometimes clearer and simpler to use callable instances than > closures. Indeed. I think __call__ has been neglected as

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread infidel
I find it useful in certain situations. In particular, I have used it along with cx_Oracle to provide a python module that dynamically mirrors a package of stored procedures in the database. Basically I had class StoredProcedure(object) and each instance of this class represented a particular sto

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | I'm wondering, are there some general cases where __call__ methods of | a user-defined class are simply indispensable? One classical example (untested, based on memory of posted code): class memoize(): def __init__(self, func):

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Paul Rubin
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: > from foo import foo > x = foo(3) > > Or did I miss the point ??? The foo module might define a bunch of additional functions that you still want to be able to access in qualified form. For example it would somewhat clean up the interface to the p

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Bruno Desthuilliers
Paul Rubin a écrit : > [EMAIL PROTECTED] writes: > >>In this particular case it was clearly unnecessary and just obfuscated the >>code. I'm wondering, are there some general cases where __call__ methods of >>a user-defined class are simply indispensable? > > > I don't know about "indispensable"

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > I don't personally use __call__ methods in my classes, but I have > encountered it every now and then here at work in code written by other > people. The other day I replaced __call__ with a more obvious method name, > so now instead of executing > > obj(foo, bar

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Paul Rubin
[EMAIL PROTECTED] writes: > In this particular case it was clearly unnecessary and just obfuscated the > code. I'm wondering, are there some general cases where __call__ methods of > a user-defined class are simply indispensable? I don't know about "indispensable" but __call__ is convenient somet

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb: > I don't personally use __call__ methods in my classes, but I have > encountered it every now and then here at work in code written by other > people. The other day I replaced __call__ with a more obvious method name, > so now instead of executing > > obj(foo, bar,

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Chris Mellon
On 8/2/07, Neil Cerutti <[EMAIL PROTECTED]> wrote: > On 2007-08-02, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > I don't personally use __call__ methods in my classes, but I > > have encountered it every now and then here at work in code > > written by other people. The other day I replaced __

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Neil Cerutti
On 2007-08-02, Neil Cerutti <[EMAIL PROTECTED]> wrote: > On 2007-08-02, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> I don't personally use __call__ methods in my classes, but I >> have encountered it every now and then here at work in code >> written by other people. The other day I replaced _

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Neil Cerutti
On 2007-08-02, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I don't personally use __call__ methods in my classes, but I > have encountered it every now and then here at work in code > written by other people. The other day I replaced __call__ > with a more obvious method name, so now instead of

__call__ considered harmful or indispensable?

2007-08-02 Thread skip
I don't personally use __call__ methods in my classes, but I have encountered it every now and then here at work in code written by other people. The other day I replaced __call__ with a more obvious method name, so now instead of executing obj(foo, bar, baz) the code in question is ob