Re: hasattr + __getattr__: I think this is Python bug

2010-07-28 Thread Ethan Furman
Bruno Desthuilliers wrote: Ethan Furman a écrit : Bruno Desthuilliers wrote: Bruno Desthuilliers a écrit : Ethan Furman a écrit : Bruno Desthuilliers wrote: Duncan Booth a écrit : (snip) Or you could create the default as a class attribute from the OP: """ I have a class (FuncDesigner o

Re: hasattr + __getattr__: I think this is Python bug

2010-07-28 Thread Bruno Desthuilliers
Ethan Furman a écrit : Bruno Desthuilliers wrote: Bruno Desthuilliers a écrit : Ethan Furman a écrit : Bruno Desthuilliers wrote: Duncan Booth a écrit : (snip) Or you could create the default as a class attribute from the OP: """ I have a class (FuncDesigner oofun) that has no attribute

Re: hasattr + __getattr__: I think this is Python bug

2010-07-27 Thread Ethan Furman
Bruno Desthuilliers wrote: Bruno Desthuilliers a écrit : Ethan Furman a écrit : Bruno Desthuilliers wrote: Duncan Booth a écrit : (snip) Or you could create the default as a class attribute from the OP: """ I have a class (FuncDesigner oofun) that has no attribute "size", but it is overlo

Re: hasattr + __getattr__: I think this is Python bug

2010-07-27 Thread Bruno Desthuilliers
Bruno Desthuilliers a écrit : Ethan Furman a écrit : Bruno Desthuilliers wrote: Duncan Booth a écrit : (snip) Or you could create the default as a class attribute from the OP: """ I have a class (FuncDesigner oofun) that has no attribute "size", but it is overloaded in __getattr__, so if s

Re: hasattr + __getattr__: I think this is Python bug

2010-07-27 Thread Bruno Desthuilliers
Ethan Furman a écrit : Bruno Desthuilliers wrote: Duncan Booth a écrit : (snip) Or you could create the default as a class attribute from the OP: """ I have a class (FuncDesigner oofun) that has no attribute "size", but it is overloaded in __getattr__, so if someone invokes "myObject.size",

Re: hasattr + __getattr__: I think this is Python bug

2010-07-26 Thread Ethan Furman
Bruno Desthuilliers wrote: Duncan Booth a écrit : Bruno Desthuilliers wrote: If you don't want to create as many Whatever instances as MyClass instances, you can create a single Whatever instance before defining your class: DEFAULT_WHATEVER = Whathever() class MyClass(object): def __

Re: hasattr + __getattr__: I think this is Python bug

2010-07-26 Thread Bruno Desthuilliers
Duncan Booth a écrit : Bruno Desthuilliers wrote: If you don't want to create as many Whatever instances as MyClass instances, you can create a single Whatever instance before defining your class: DEFAULT_WHATEVER = Whathever() class MyClass(object): def __init__(self, x, y):

Re: hasattr + __getattr__: I think this is Python bug

2010-07-26 Thread Duncan Booth
Bruno Desthuilliers wrote: > If you don't want to create as many Whatever instances as MyClass > instances, you can create a single Whatever instance before defining > your class: > > DEFAULT_WHATEVER = Whathever() > > class MyClass(object): > def __init__(self, x, y): > self.x

Re: hasattr + __getattr__: I think this is Python bug

2010-07-26 Thread Bruno Desthuilliers
dmitrey a écrit : (snip) This doesn't stack with the following issue: sometimes user can write in code "myObject.size = (some integer value)" and then it will be involved in future calculations as ordinary fixed value; if user doesn't supply it, but myObject.size is involved in calculations, the

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread Ian Kelly
On Tue, Jul 20, 2010 at 9:39 AM, dmitrey wrote: >>How about using a property instead of the __getattr__() hook? A property is a >>computed attribute that (among other things) plays much nicer with hasattr. > > Could anyone provide an example of it to be implemented, taking into > account that a u

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread Robert Kern
On 7/20/10 11:39 AM, dmitrey wrote: e.g. one that just looks in the object's dictionary so as to avoid returning true for properties or other such fancy attributes. So can anyone explain me how to look into object's dict? As I have wrote, "something in dir(...)" requires O(numOfFields) while I

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread Robert Kern
On 7/20/10 6:59 AM, dmitrey wrote: On Jul 20, 1:37 pm, Chris Rebert wrote: Least ugly suggestion: Just don't use hasattr(); use your `x in dir(y)` trick instead. something in dir() consumes O(n) operations for lookup, while hasattr or getattr() require O(log(n)). It matters for me, because

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread Duncan Booth
dmitrey wrote: >> e.g. one that just looks in the object's dictionary so as to avoid >> returning true for properties or other such fancy attributes. > > So can anyone explain me how to look into object's dict? As I have > wrote, "something in dir(...)" requires O(numOfFields) while I would > l

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread Jean-Michel Pichavant
dmitrey wrote: On 20 июл, 15:00, Jean-Michel Pichavant wrote: dmitrey wrote: hi all, I have a class (FuncDesigner oofun) that has no attribute "size", but it is overloaded in __getattr__, so if someone invokes "myObject.size", it is generated (as another oofun) and connected to myObjec

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread dmitrey
On 20 июл, 18:39, Neil Cerutti wrote: > On 2010-07-20, dmitrey wrote: > > > This doesn't stack with the following issue: sometimes user can > > write in code "myObject.size = (some integer value)" and then > > it will be involved in future calculations as ordinary fixed > > value; if user doesn't

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread Neil Cerutti
On 2010-07-20, dmitrey wrote: > This doesn't stack with the following issue: sometimes user can > write in code "myObject.size = (some integer value)" and then > it will be involved in future calculations as ordinary fixed > value; if user doesn't supply it, but myObject.size is involved > in calc

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread dmitrey
> e.g. one that just looks in the object's dictionary so as to avoid returning > true for properties or other such fancy attributes. So can anyone explain me how to look into object's dict? As I have wrote, "something in dir(...)" requires O(numOfFields) while I would like to use o(log(n)) >How

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread dmitrey
On 20 июл, 15:00, Jean-Michel Pichavant wrote: > dmitrey wrote: > > hi all, > > I have a class (FuncDesigner oofun) that has no attribute "size", but > > it is overloaded in __getattr__, so if someone invokes > > "myObject.size", it is generated (as another oofun) and connected to > > myObject as

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread Christian Heimes
Am 20.07.2010 12:10, schrieb dmitrey: > hi all, > I have a class (FuncDesigner oofun) that has no attribute "size", but > it is overloaded in __getattr__, so if someone invokes > "myObject.size", it is generated (as another oofun) and connected to > myObject as attribute. How about using a propert

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread Jean-Michel Pichavant
dmitrey wrote: hi all, I have a class (FuncDesigner oofun) that has no attribute "size", but it is overloaded in __getattr__, so if someone invokes "myObject.size", it is generated (as another oofun) and connected to myObject as attribute. So, when I invoke in other code part "hasattr(myObject,

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread Duncan Booth
dmitrey wrote: > hi all, > I have a class (FuncDesigner oofun) that has no attribute "size", but > it is overloaded in __getattr__, so if someone invokes > "myObject.size", it is generated (as another oofun) and connected to > myObject as attribute. > > So, when I invoke in other code part "hasa

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread dmitrey
On Jul 20, 1:37 pm, Chris Rebert wrote: > On Tue, Jul 20, 2010 at 3:10 AM, dmitrey wrote: > > hi all, > > I have a class (FuncDesigner oofun) that has no attribute "size", but > > it is overloaded in __getattr__, so if someone invokes > > "myObject.size", it is generated (as another oofun) and co

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread Chris Rebert
On Tue, Jul 20, 2010 at 3:10 AM, dmitrey wrote: > hi all, > I have a class (FuncDesigner oofun) that has no attribute "size", but > it is overloaded in __getattr__, so if someone invokes > "myObject.size", it is generated (as another oofun) and connected to > myObject as attribute. > > So, when I

hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread dmitrey
hi all, I have a class (FuncDesigner oofun) that has no attribute "size", but it is overloaded in __getattr__, so if someone invokes "myObject.size", it is generated (as another oofun) and connected to myObject as attribute. So, when I invoke in other code part "hasattr(myObject, 'size')", instead