Re: Question regarding objects in __call__() methods

2018-03-25 Thread Arshpreet Singh
On Monday, 26 March 2018 11:32:51 UTC+5:30, dieter wrote: > Fürther inspection utilities: "dir", "vars" and the "inspect" module. > Read the documentation to find out what they do. Thanks, Dieter, That is really helpful! -- https://mail.python.org/mailman/listinfo/python-list

Re: Question regarding objects in __call__() methods

2018-03-25 Thread dieter
Arshpreet Singh writes: > ... > As debugging the code I got at line 10. I am sending a request to particular > API and returning a request_object . further deep down it generates the > "response_object" as from my requirements that should be JSON object but I am > only getting Python-Object in

Question regarding objects in __call__() methods

2018-03-25 Thread Arshpreet Singh
nse. I am also able to call __call__ method something like this: def hierarchy_attach(env, parent): svc = IMS(env) svc(parent) -- https://mail.python.org/mailman/listinfo/python-list

Re: what exactly does type.__call__ do?

2017-11-02 Thread Jason Maldonis
sion -- I'm not actually using a Singleton, but it's an easy situation to think about. I'd like to ask a couple follow up questions here: By using... @classmethod def normal_constructor(cls, *args, **kwargs): return type.__call__(cls, *args, **kwargs) # Aside: Yes, the `cls` do

Re: what exactly does type.__call__ do?

2017-11-01 Thread Steve D'Aprano
f normal_constructor(cls, *args, **kwargs): > return type.__call__(*args, **kwargs) Untested, but I think that should be: return type.__call__(cls, *args, **kwargs) > @classmethod > def normal_constructor(cls, *args, **kwargs): > return super(???).__call__(*args, **kw

Re: what exactly does type.__call__ do?

2017-11-01 Thread Jason Maldonis
on't often deal with multiple class constructors, so I'm a bit new to that territory and I'm trying to delve into the details of how python classes are constructed (namely, whether `type.__call__` does more than just call `cls.__new__` and `self.__init__`). Thanks for the help too.

Re: what exactly does type.__call__ do?

2017-11-01 Thread Jason Maldonis
Thanks for the reply. And I think I wasn't clear enough. I was wondering what the metaclass `type`'s `type.__call__` does explicitly. I'm reasonably comfortable writing metaclasses when I need them, and I understand how `.__call__` works for non-metaclass objects. In my first ema

what exactly does type.__call__ do?

2017-11-01 Thread Jason Maldonis
this metaclass from being used. To do that, I think I just make a @classmethod constructor function. However, I can imagine a few different ways of writing this: @classmethod def normal_constructor(cls, *args, **kwargs): return type.__call__(*args, **kwargs) @classmethod def normal_constru

Re: What happens when a __call__ function is defined in both class and object ?

2017-10-19 Thread Thomas Jollans
On 2017-10-19 10:11, ast wrote: > Surprisingly, __call__ from the class is called, not the > one defined in the object. Why ? That's just how dunder methods like __call__ work. See https://docs.python.org/3/reference/datamodel.html#special-method-names To quote the docs: > For

Re: What happens when a __call__ function is defined in both class and object ?

2017-10-19 Thread Chris Angelico
t;self.a = 2 >> self.f = lambda : print("f from object") >> self.__call__ = lambda : print("__call__ from object") >> def __call__(self): >>print("__call__ from class Test") >> def f(self): >>

Re: What happens when a __call__ function is defined in both class and object ?

2017-10-19 Thread Chris Angelico
On Thu, Oct 19, 2017 at 7:11 PM, ast wrote: > Hello, please have a look at following code snippet > (python 3.4.4) > > class Test: > >a = 1 > >def __init__(self): >self.a = 2 >self.f = lambda : print("f from object") > se

What happens when a __call__ function is defined in both class and object ?

2017-10-19 Thread ast
Hello, please have a look at following code snippet (python 3.4.4) class Test: a = 1 def __init__(self): self.a = 2 self.f = lambda : print("f from object") self.__call__ = lambda : print("__call__ from object") def __call__(self):

Re: A __call__ "method" which is itself another callable class instance?

2015-05-08 Thread Chris Angelico
es? I've never actually done it, but there've been times when I've considered setting __call__ to be a class, rather than an actual function. (Though the time I wanted it, I was wanting to set __call__ on a module, and I ended up not bothering with the hassle that that entails.) Python c

A __call__ "method" which is itself another callable class instance?

2015-05-08 Thread Skip Montanaro
= func.func_globals elif inspect.isbuiltin(func): func_globals = sys.modules[func.__module__].__dict__ elif inspect.ismethoddescriptor(func): raise TypeError("Can't get globals of a method descriptor") What if func is actually an instance of a class with a __call__ method? S

Re: [Python-Dev] Dinamically set __call__ method

2014-11-13 Thread Lie Ryan
On 05/11/14 06:15, Roberto Martínez wrote: The thing with this is tricky. I need the change in the instance, > not in the class, because I have multiple instances and all of > them must have different implementations of __call__. Why not just use functions with closure if that's wh

Re: [Python-Dev] Dinamically set __call__ method

2014-11-13 Thread Fabio Zadrozny
re -- not sure how much could break because of that >> though >> > > Something fairly fundamental that would break is classs > instantiation! You instantiate a class by calling it, so if > a(x) were implemented as a.__call__(x), and class C had > a __call__ method, then C(

Re: [Python-Dev] Dinamically set __call__ method

2014-11-12 Thread Gregory Ewing
te a class by calling it, so if a(x) were implemented as a.__call__(x), and class C had a __call__ method, then C() would invoke that method instead of instantiating C. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: [Python-Dev] Dinamically set __call__ method

2014-11-12 Thread Ian Kelly
pens the way it does > though, so, can someone from python-dev give some background of why that's > the way it is? i.e.: instead of the approach which would seem simpler which > would do getattr(a, '__call__') instead of > type(a).__dict__['__call__'].__get__(a,

Re: [Python-Dev] Dinamically set __call__ method

2014-11-12 Thread Fabio Zadrozny
On Tue, Nov 11, 2014 at 5:43 AM, Ian Kelly wrote: > On Sat, Nov 8, 2014 at 3:31 PM, Gregory Ewing > wrote: > > (BTW, I'm actually surprised that this technique makes c callable. > > There must be more going on that just "look up __call__ in the class > > obje

Re: [Python-Dev] Dinamically set __call__ method

2014-11-10 Thread Ian Kelly
On Sat, Nov 8, 2014 at 3:31 PM, Gregory Ewing wrote: > (BTW, I'm actually surprised that this technique makes c callable. > There must be more going on that just "look up __call__ in the class > object", because evaluating C.__call__ just returns the descriptor &g

Re: [Python-Dev] Dinamically set __call__ method

2014-11-09 Thread Ethan Furman
ng on that just "look up __call__ in the class object", because evaluating C.__call__ just returns the descriptor and doesn't invoking the descriptor mechanism.) which seems to clash with what you just said. -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list

Re: [Python-Dev] Dinamically set __call__ method

2014-11-09 Thread Steven D'Aprano
nstance, though. > Normally, if you look up an attribute on a class, > the descriptor protocol doesn't get triggered. Since this whole thread is about giving instances their own individual __call__ methods, I don't think that doing the look-up on the class is part of the requiremen

Re: [Python-Dev] Dinamically set __call__ method

2014-11-09 Thread Gregory Ewing
Ethan Furman wrote: And the thing going on is the normal python behavior (in __getattribute__, I believe) of examining the returned attribute to see if it is a descriptor, and if so invoking it. Only if you look it up through the instance, though. Normally, if you look up an attribute on a cla

Re: [Python-Dev] Dinamically set __call__ method

2014-11-08 Thread Ethan Furman
On 11/08/2014 02:31 PM, Gregory Ewing wrote: Seems to depend on how you get hold of the object you're inspecting the signature of. I did an experiment: class C(object): @property def __call__(self): return self.call def f(x, y): print("Called f with %s, %

Re: [Python-Dev] Dinamically set __call__ method

2014-11-08 Thread Gregory Ewing
Ethan Furman wrote: On 11/06/2014 10:59 PM, dieter wrote: A possibility to get the original approach implemented looks like: make "__call__" a descriptor on the class which looks up the real method on the instance. This still wouldn't get the signatrue correct, th

Re: [Python-Dev] Dinamically set __call__ method

2014-11-08 Thread Ethan Furman
to either look at a function creating factory, a class creating factory, or a meta-class. +1. Overriding __call__() within the class definition, over and over again, with different function, looks awkward to me. A possibility to get the original approach implemented looks like: make

Re: [Python-Dev] Dinamically set __call__ method

2014-11-07 Thread dieter
> for each instance, you may to either look at a >>>> function creating factory, a class creating factory, or a meta-class. >>> >>> +1. Overriding __call__() within the class definition, over and over >>> again, with different function, looks awkward to

Re: [Python-Dev] Dinamically set __call__ method

2014-11-07 Thread Ethan Furman
factory, or a meta-class. +1. Overriding __call__() within the class definition, over and over again, with different function, looks awkward to me. A possibility to get the original approach implemented looks like: make "__call__" a descriptor on the class which looks up the real

Re: [Python-Dev] Dinamically set __call__ method

2014-11-06 Thread dieter
factory, or a meta-class. > > +1. Overriding __call__() within the class definition, over and over again, > with different function, looks awkward to me. A possibility to get the original approach implemented looks like: make "__call__" a descriptor on the class which

Re: [Python-Dev] Dinamically set __call__ method

2014-11-06 Thread Steven D'Aprano
Roberto Martínez wrote: > Yikes, I didn't realize the difference in inheritance. > > The thing with this is tricky. I need the change in the instance, not in > the class, because I have multiple instances and all of them must have > different implementations of __call__. &g

Re: [Python-Dev] Dinamically set __call__ method

2014-11-06 Thread John Ladasky
On Tuesday, November 4, 2014 11:12:31 AM UTC-8, Ethan Furman wrote: > If you really absolutely positively have to have the signature be correct for > each instance, you may to either look at a > function creating factory, a class creating factory, or a meta-class. +1. Overriding

Re: [Python-Dev] Dinamically set __call__ method

2014-11-04 Thread alex23
On 11/04/2014 08:52 AM, Roberto Martínez wrote: I am trying to replace dinamically the __call__ method of an object using setattr. Example: $ cat testcall.py class A: def __init__(self): setattr(self, '__call__', self.newcall) def __call__(self):

Re: [Python-Dev] Dinamically set __call__ method

2014-11-04 Thread Ethan Furman
On 11/04/2014 11:23 AM, Nathaniel Smith wrote: (Or alternatively I guess you could go all in: Iä! Iä! Metaclasses Fhtagn!) Metaclasses aren't that bad! I've written one. And the dizzy spells are getting better! -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list

Re: [Python-Dev] Dinamically set __call__ method

2014-11-04 Thread Nathaniel Smith
On Tue, Nov 4, 2014 at 7:15 PM, Roberto Martínez wrote: > > > On Tue, Nov 4, 2014 at 8:06 PM, Skip Montanaro > wrote: >> >> >> On Tue, Nov 4, 2014 at 1:01 PM, Roberto Martínez >> wrote: >>> >>> The workaround of calling a different method

Re: [Python-Dev] Dinamically set __call__ method

2014-11-04 Thread Roberto Martínez
On Tue, Nov 4, 2014 at 8:06 PM, Skip Montanaro wrote: > > On Tue, Nov 4, 2014 at 1:01 PM, Roberto Martínez < > robertomartin...@gmail.com> wrote: > >> The workaround of calling a different method inside __call__ is not valid >> for my case because I want to change t

Re: [Python-Dev] Dinamically set __call__ method

2014-11-04 Thread Ethan Furman
On 11/04/2014 11:01 AM, Roberto Martínez wrote: (Ethan, sorry for posting to python-dev, I thought that it was an implementation detail of CPython 3.X) No worries. It's good practice to post here first, just in case. ;) -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list

Re: [Python-Dev] Dinamically set __call__ method

2014-11-04 Thread Ethan Furman
On 11/04/2014 11:01 AM, Roberto Martínez wrote: Yikes, I didn't realize the difference in inheritance. The thing with this is tricky. I need the change in the instance, not in the class, because I have multiple instances and all of them must have different implementations of __call__.

Re: [Python-Dev] Dinamically set __call__ method

2014-11-04 Thread Skip Montanaro
On Tue, Nov 4, 2014 at 1:01 PM, Roberto Martínez wrote: > The workaround of calling a different method inside __call__ is not valid > for my case because I want to change the *signature* of the function also > -for introspection reasons. You could define __call__ like so: def __ca

Re: [Python-Dev] Dinamically set __call__ method

2014-11-04 Thread Roberto Martínez
Yikes, I didn't realize the difference in inheritance. The thing with this is tricky. I need the change in the instance, not in the class, because I have multiple instances and all of them must have different implementations of __call__. The workaround of calling a different method i

Re: [Python-Dev] Dinamically set __call__ method

2014-11-04 Thread Ethan Furman
This list is for the development _of_ Python, not development _with_ Python. Try asking on Python List. (forwarding...) On 11/04/2014 08:52 AM, Roberto Martínez wrote: I am trying to replace dinamically the __call__ method of an object using setattr. Example: $ cat testcall.py class A

How to np.vectorize __call__ method

2013-11-14 Thread Yaşar Arabacı
/Empirical_distribution_function) using vectorized numpy methods. Here is the **correct** solution to problem: class ecdf: def __init__(self, observations): self.observations = np.asarray(observations) def __call__(self, x): return np.mean(self.observations <= x)

Re: Overriding of the type.__call__() method in a metaclass

2013-10-06 Thread Marco Buttu
On 10/07/2013 04:27 AM, Steven D'Aprano wrote: On Sun, 06 Oct 2013 20:17:33 +0200, Marco Buttu wrote: > > >>> class FooMeta(type): >... def __call__(metacls, name, bases, namespace): >... print("FooMeta.__call__()") ... > From what I undes

Re: Overriding of the type.__call__() method in a metaclass

2013-10-06 Thread Steven D'Aprano
On Sun, 06 Oct 2013 20:17:33 +0200, Marco Buttu wrote: > Hi all, I have a question about class creation and the __call__ method. > I have the following metaclass: > > >>> class FooMeta(type): > ... def __call__(metacls, name, bases, namespace): > ...prin

Re: Overriding of the type.__call__() method in a metaclass

2013-10-06 Thread Peter Otten
Marco Buttu wrote: > Hi all, I have a question about class creation and the __call__ method. > I have the following metaclass: > > >>> class FooMeta(type): > ... def __call__(metacls, name, bases, namespace): > ... print("FooMeta.__call__()") &

Overriding of the type.__call__() method in a metaclass

2013-10-06 Thread Marco Buttu
Hi all, I have a question about class creation and the __call__ method. I have the following metaclass: >>> class FooMeta(type): ... def __call__(metacls, name, bases, namespace): ... print("FooMeta.__call__()") From what I undestood, at the end of the clas

Re: The type.__call__() method manages the calls to __new__ and __init__?

2012-11-20 Thread Ian Kelly
On Tue, Nov 20, 2012 at 10:29 AM, Marco wrote: > Because when I call an instance the __call__ method is called, and because > the classes are instances of type, I thought when I call a Foo class this > imply the call type.__call__(Foo), and so this one manages the Foo.__new__ > and

The type.__call__() method manages the calls to __new__ and __init__?

2012-11-20 Thread Marco
when I call an instance the __call__ method is called, and because the classes are instances of type, I thought when I call a Foo class this imply the call type.__call__(Foo), and so this one manages the Foo.__new__ and Foo.__init__ calls: >>> class Foo: ... def __

Re: How to access the document for __call__ from command line?

2012-10-18 Thread Terry Reedy
On 10/18/2012 10:30 PM, Peng Yu wrote: Hi, reference.pdf from python document has the following description. It is not accessible from help() in the command line. Is there an alternative so that I can quickly access these class attributes or method names from the command line? object.__call__

How to access the document for __call__ from command line?

2012-10-18 Thread Peng Yu
Hi, reference.pdf from python document has the following description. It is not accessible from help() in the command line. Is there an alternative so that I can quickly access these class attributes or method names from the command line? object.__call__(self [, args... ]) Called when the

Re: The Magick of __call__ (Or, Digging Deeper Than I Ought To)

2011-04-01 Thread Chris Angelico
What I was thinking was something along the lines of a loop-back reference in the wrapper itself. So for instance: Foo.__call__ = wrapper(Foo) The wrapper would be created with a __call__ method of itself: self.__call__ = self That would not require a dictionary, it's just a special case

Re: The Magick of __call__ (Or, Digging Deeper Than I Ought To)

2011-04-01 Thread Terry Reedy
On 4/1/2011 11:07 AM, Corey Richardson wrote: All callables (things you can foo(bar)) are really just objects that implement the __call__ method, as far as I understand. > Well then, that would appear to make methods themselves callable, Method are just function objects that are cl

Re: The Magick of __call__ (Or, Digging Deeper Than I Ought To)

2011-04-01 Thread Chris Angelico
On Sat, Apr 2, 2011 at 2:07 AM, Corey Richardson wrote: > All callables (things you can foo(bar)) are really just objects that > implement the __call__ method, as far as I understand. Well then, that > would appear to make methods themselves callable, so let's do a little &g

The Magick of __call__ (Or, Digging Deeper Than I Ought To)

2011-04-01 Thread Corey Richardson
All callables (things you can foo(bar)) are really just objects that implement the __call__ method, as far as I understand. Well then, that would appear to make methods themselves callable, so let's do a little playing around... lavos@lavos ~ $ python Python 2.6.6 (r266:84292, Sep 15 2010,

Re: instance has no __call__ method

2010-12-11 Thread Steve Holden
t;, "copyright", "credits" or "license" for more information. >>>> import Muffle_ZeroDivision >>>> calc = Muffle_ZeroDivision.MuffledCalculator() >>>> calc = ('10/2') >>>> cal

Re: instance has no __call__ method

2010-12-10 Thread Dave Angel
ion calc = Muffle_ZeroDivision.MuffledCalculator() calc = ('10/2') calc = Muffle_ZeroDivision.MuffledCalculator() calc('10/2') Traceback (most recent call last): File "", line 1, in AttributeError: MuffledCalculator instance has no __call__ method ---

instance has no __call__ method

2010-12-10 Thread frank cui
lc = Muffle_ZeroDivision.MuffledCalculator() >>> calc = ('10/2') >>> calc = Muffle_ZeroDivision.MuffledCalculator() >>> calc('10/2') Traceback (most recent call last): File "", line 1, in AttributeError: MuffledCalculator instance has no __call__ method --

Re: Decorator to inject function into __call__ of a class

2010-03-13 Thread Steven D'Aprano
hat you want, then this is probably the simplest approach: Start by adding delegation to the Compute class: class Compute(object): def __init__(self, something): self.something = something def __call__(self, *args, **kwargs): return self.function(*args, **kwargs) Then you can init

Re: Decorator to inject function into __call__ of a class

2010-03-13 Thread Jon Clements
andling. > >> > I have 'B' and 'C' which specialise upon 'A' > > >> > What I'd like to achieve is something similar to: > > >> > @inject(B): > >> >  def some_function(a, b): > >> >    

Re: Decorator to inject function into __call__ of a class

2010-03-13 Thread Stephen Hansen
On Sat, Mar 13, 2010 at 8:19 AM, Jon Clements wrote: > The name 'some_function' is completely redundant -- don't need it, > don't actually care about the function afterwards, as long as it > becomes a __call__ of a 'B' *instance*. > Special methods ar

Re: Decorator to inject function into __call__ of a class

2010-03-13 Thread Jack Diederich
pon 'A' >> >> > What I'd like to achieve is something similar to: >> >> > @inject(B): >> >  def some_function(a, b): >> >     pass # something useful >> >> > The name 'some_function' is completely redundant -- don't need

Re: Decorator to inject function into __call__ of a class

2010-03-13 Thread Jon Clements
; @inject(B): > >  def some_function(a, b): > >     pass # something useful > > > The name 'some_function' is completely redundant -- don't need it, > > don't actually care about the function afterwards, as long as it > > becomes a __call__ of a

Re: Decorator to inject function into __call__ of a class

2010-03-13 Thread Patrick Maupin
a, b): > > >      pass # something useful > > > So, just typing at the keyboard here, you mean something like: > > > class InjectClass(object): > >     def __init__(self, func, *args, **kw): > >         self.func = func > >         self.args = args >

Re: Decorator to inject function into __call__ of a class

2010-03-13 Thread Jack Diederich
e name 'some_function' is completely redundant -- don't need it, > don't actually care about the function afterwards, as long as it > becomes a __call__ of a 'B' *instance*. > > I've basically got a huge list of functions, which need to be the > cal

Re: Decorator to inject function into __call__ of a class

2010-03-13 Thread Jon Clements
ard here, you mean something like: > > class InjectClass(object): >     def __init__(self, func, *args, **kw): >         self.func = func >         self.args = args >         self.kw = kw >     def __call__(self): >         self.func(*self.args, **self.kw) > > Or exactl

Re: Decorator to inject function into __call__ of a class

2010-03-13 Thread Patrick Maupin
__(self, func, *args, **kw): self.func = func self.args = args self.kw = kw def __call__(self): self.func(*self.args, **self.kw) Or exactly what are you looking for? Pat -- http://mail.python.org/mailman/listinfo/python-list

Decorator to inject function into __call__ of a class

2010-03-13 Thread Jon Clements
'C' which specialise upon 'A' What I'd like to achieve is something similar to: @inject(B): def some_function(a, b): pass # something useful The name 'some_function' is completely redundant -- don't need it, don't actually care about the function a

Re: Can't define __call__ within __init__?

2010-03-11 Thread Steven D'Aprano
On Thu, 11 Mar 2010 07:56:59 -0500, Neal Becker wrote: > The example I showed was just a toy problem. The real problem is I > expect to call a function many times, and I want to avoid the overhead > of the 'if blah' everytime. Unless the __call__ methods are very small,

Re: Can't define __call__ within __init__?

2010-03-11 Thread Steven D'Aprano
On Thu, 11 Mar 2010 08:20:14 -0800, Steve Howell wrote: >> (2) special methods like __call__ are only called on the class, not the >> instance, so you can't give each instance its own method. >> >> > Are you sure about that? This program prints 1, 2, 1, 2. T

Re: Can't define __call__ within __init__?

2010-03-11 Thread Peter Otten
Steve Howell wrote: > On Mar 10, 7:18 pm, Steven D'Aprano > wrote: >> (2) special methods like __call__ are only called on the class, not the >> instance, so you can't give each instance its own method. > Are you sure about that? This program prints 1, 2, 1, 2.

Re: Can't define __call__ within __init__?

2010-03-11 Thread Steve Howell
On Mar 10, 7:18 pm, Steven D'Aprano wrote: > On Wed, 10 Mar 2010 08:12:14 -0500, Neal Becker wrote: > > Want to switch __call__ behavior.  Why doesn't this work?  What is the > > correct way to write this? > > > class X (object): > >     def

Re: Can't define __call__ within __init__?

2010-03-11 Thread MRAB
Andre Engels wrote: On Thu, Mar 11, 2010 at 2:30 PM, Steve Holden wrote: The example I showed was just a toy problem. The real problem is I expect to call a function many times, and I want to avoid the overhead of the 'if blah' everytime. This is a premature optimization. First, make it wor

Re: Can't define __call__ within __init__?

2010-03-11 Thread Andre Engels
On Thu, Mar 11, 2010 at 2:30 PM, Steve Holden wrote: >> The example I showed was just a toy problem.  The real problem is >> I expect to call a function many times, and I want to avoid the overhead of >> the 'if blah' everytime. >> > This is a premature optimization. First, make it work. Then (if

Re: Can't define __call__ within __init__?

2010-03-11 Thread Steve Holden
Neal Becker wrote: > Steven D'Aprano wrote: > >> On Wed, 10 Mar 2010 08:12:14 -0500, Neal Becker wrote: >> >>> Want to switch __call__ behavior. Why doesn't this work? What is the >>> correct way to write this? >>> >>> class

Re: Can't define __call__ within __init__?

2010-03-11 Thread Neal Becker
Steven D'Aprano wrote: > On Wed, 10 Mar 2010 08:12:14 -0500, Neal Becker wrote: > >> Want to switch __call__ behavior. Why doesn't this work? What is the >> correct way to write this? >> >> class X (object): >> def __init__(self, i): >>

Re: Can't define __call__ within __init__?

2010-03-10 Thread Steven D'Aprano
On Wed, 10 Mar 2010 08:12:14 -0500, Neal Becker wrote: > Want to switch __call__ behavior. Why doesn't this work? What is the > correct way to write this? > > class X (object): > def __init__(self, i): > if i == 0: > def __call__ (self):

Re: Can't define __call__ within __init__?

2010-03-10 Thread Neal Becker
Robert Kern wrote: > On 2010-03-10 12:23 PM, Neal Becker wrote: >> Duncan Booth wrote: >> ... >>> >>> P.S. I don't know what you did in your post but your Followup-To header >>> is pointing to a group on gmane which makes extra work for me replying. >>> Please don't do that. >> >> I'm sorry about

Re: Can't define __call__ within __init__?

2010-03-10 Thread Robert Kern
On 2010-03-10 12:23 PM, Neal Becker wrote: Duncan Booth wrote: ... P.S. I don't know what you did in your post but your Followup-To header is pointing to a group on gmane which makes extra work for me replying. Please don't do that. I'm sorry about that, there is some bad interaction between

Re: Can't define __call__ within __init__?

2010-03-10 Thread Robert Kern
On 2010-03-10 13:42 PM, Neal Becker wrote: Duncan Booth wrote: Neal Becker wrote: Duncan Booth wrote: ... P.S. I don't know what you did in your post but your Followup-To header is pointing to a group on gmane which makes extra work for me replying. Please don't do that. I'm sorry about

Re: Can't define __call__ within __init__?

2010-03-10 Thread Neal Becker
Duncan Booth wrote: > Neal Becker wrote: > >> Duncan Booth wrote: >> ... >>> >>> P.S. I don't know what you did in your post but your Followup-To >>> header is pointing to a group on gmane which makes extra work for me >>> replying. Please don't do that. >> >> I'm sorry about that, there is so

Re: Can't define __call__ within __init__?

2010-03-10 Thread Duncan Booth
Neal Becker wrote: > Duncan Booth wrote: > ... >> >> P.S. I don't know what you did in your post but your Followup-To >> header is pointing to a group on gmane which makes extra work for me >> replying. Please don't do that. > > I'm sorry about that, there is some bad interaction between gmane'

Re: Can't define __call__ within __init__?

2010-03-10 Thread Neal Becker
Duncan Booth wrote: ... > > P.S. I don't know what you did in your post but your Followup-To header is > pointing to a group on gmane which makes extra work for me replying. > Please don't do that. I'm sorry about that, there is some bad interaction between gmane's nntp- smtp gateway and python's

Re: Can't define __call__ within __init__?

2010-03-10 Thread Duncan Booth
our its usually best to use different classes. You can keep all the common behaviour in a base class and just override the __call__ method for the different behaviour. Then use a factory function to decide which class to instantiate or else override __new__ and make the decision there. e.g.

Re: Can't define __call__ within __init__?

2010-03-10 Thread Matt Nordhoff
Neal Becker wrote: > Simon Brunning wrote: > >> On 10 March 2010 13:12, Neal Becker wrote: >>> Want to switch __call__ behavior. Why doesn't this work? What is the >>> correct way to write this? >>> >>> class X (object): >>>

Re: Can't define __call__ within __init__?

2010-03-10 Thread Neal Becker
Simon Brunning wrote: > On 10 March 2010 13:12, Neal Becker wrote: >> Want to switch __call__ behavior. Why doesn't this work? What is the >> correct way to write this? >> >> class X (object): >> def __init__(self, i): >> if i == 0: >> def __

Re: Can't define __call__ within __init__?

2010-03-10 Thread Mark Lawrence
Neal Becker wrote: Want to switch __call__ behavior. Why doesn't this work? What is the correct way to write this? class X (object): def __init__(self, i): if i == 0: def __call__ (self): return 0 else: def __call_

Re: Can't define __call__ within __init__?

2010-03-10 Thread Simon Brunning
On 10 March 2010 13:12, Neal Becker wrote: > Want to switch __call__ behavior.  Why doesn't this work?  What is the > correct way to write this? > > class X (object): >    def __init__(self, i): >        if i == 0: >            def __call__ (self): >        

Can't define __call__ within __init__?

2010-03-10 Thread Neal Becker
Want to switch __call__ behavior. Why doesn't this work? What is the correct way to write this? class X (object): def __init__(self, i): if i == 0: def __call__ (self): return 0 else: def __call_ (self): return

Re: SocketServer error: AttributeError: instance has no __call__ method

2010-02-10 Thread Gabriel Genellina
ck (most recent call last): File "/usr/lib/python2.6/SocketServer.py", line 320, in finish_request self.RequestHandlerClass(request, client_address, self) AttributeError: Negotiator instance has no __call__ method class ServerNegotiat

SocketServer error: AttributeError: instance has no __call__ method

2010-02-10 Thread Jordan Apgar
tServer.py", line 320, in finish_request self.RequestHandlerClass(request, client_address, self) AttributeError: Negotiator instance has no __call__ method here's the handler and my server: #server side negotiator from message import message from share

Re: ABCs, functions, and __call__ (Python3)

2009-01-16 Thread andrew cooke
On Jan 16, 10:13 pm, Christian Heimes wrote: > Any callable in Python 3.0 has a "__call__" attribute. Aha! Thanks! Andrew -- http://mail.python.org/mailman/listinfo/python-list

Re: ABCs, functions, and __call__ (Python3)

2009-01-16 Thread Christian Heimes
andrew cooke schrieb: > I think I'm missing something obvious here, so apologies in advance. > > I'd like to be able to test whether something is a function or > implements __call__. Now obviously I can do that as two separate > tests, but I though this was what ABCs we

ABCs, functions, and __call__ (Python3)

2009-01-16 Thread andrew cooke
I think I'm missing something obvious here, so apologies in advance. I'd like to be able to test whether something is a function or implements __call__. Now obviously I can do that as two separate tests, but I though this was what ABCs were for. However, for the life of me I cannot

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__ >>> obscu

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 withou

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__ >>> obscu

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 insta

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 don

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Carl Banks
On Aug 2, 4:27 pm, Paul Rubin <http://[EMAIL PROTECTED]> 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 > >

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

  1   2   >