Re: Working with method-wrapper objects

2005-05-03 Thread Dr. Peer Griebel
Bengt Richter wrote: > On Thu, 28 Apr 2005 11:33:04 +0200, "Dr. Peer Griebel" <[EMAIL PROTECTED]> > wrote: > > >>Peer Dr. Griebel wrote: > > [..] > >>>Why has [].__str__ a different type than object.__str__? >>>Why is object.__str__ a routine while object().__str__ not? > > Why wouldn't you e

Re: Working with method-wrapper objects

2005-04-29 Thread Bengt Richter
On Thu, 28 Apr 2005 11:33:04 +0200, "Dr. Peer Griebel" <[EMAIL PROTECTED]> wrote: >Peer Dr. Griebel wrote: [..] >> Why has [].__str__ a different type than object.__str__? >> Why is object.__str__ a routine while object().__str__ not? Why wouldn't you expect different types? Those are different e

Re: Working with method-wrapper objects

2005-04-28 Thread Steven Bethard
Dr. Peer Griebel wrote: Why has [].__str__ a different type than object.__str__? Why is object.__str__ a routine while object().__str__ not? Well, I don't know why inspect.isroutine does what it does, but if you really need to detect these, can you do something like: py> MethodWrapperType = type(

Re: Working with method-wrapper objects

2005-04-28 Thread Dr. Peer Griebel
Peer Dr. Griebel wrote: I think I was a little bit unspecific in my last mail. I would like to see some description about method-wrapper and wrapper_descriptor objects. I dont' understand the following behaviour: type([].__str__) type(object.__str__) type(object().__str__) import inspect inspe

Re: Working with method-wrapper objects

2005-04-19 Thread Peer Dr. Griebel
I think I was a little bit unspecific in my last mail. I would like to see some description about method-wrapper and wrapper_descriptor objects. I dont' understand the following behaviour: >>> type([].__str__) >>> type(object.__str__) >>> type(object().__str__) >>> import inspect >>> inspect

Working with method-wrapper objects

2005-04-18 Thread Peer Dr. Griebel
Hi, I'm currently working on a Python Management Console. During inspection of my objects I stumbled over method-wrapper objects. Such an object may be obtained e.g. as method_wrapper = [].__str__ My problem is: This object is not a method, not a function, not a method descriptor. A

Re: Wrapper objects

2004-12-11 Thread Bengt Richter
On 10 Dec 2004 15:03:01 -0800, [EMAIL PROTECTED] wrote: >>Well, that could be a feature, depending on what your use case is. >>Or you could make a method for adding methods, I suppose. >>A perfectly transparent wrap of obj would be to do nothing ;-) >>What do you actually want to do? > >Actually,

Re: Wrapper objects

2004-12-10 Thread Nick Coghlan
[EMAIL PROTECTED] wrote: The wrapper objects needs to work as dictionary keys, to support printing, concatenation/addition, getitem/setitem and such things... In that case, identifying exactly which operations you want to support, and using a metaclass based approach like mine or Bengt's s

Re: Wrapper objects

2004-12-10 Thread redhog
>Well, that could be a feature, depending on what your use case is. >Or you could make a method for adding methods, I suppose. >A perfectly transparent wrap of obj would be to do nothing ;-) >What do you actually want to do? Actually, the very best would if only type(), isinstance() and the is-key

Re: Wrapper objects

2004-12-10 Thread redhog
This means my code is literally filled with calls to getValue(), which I would like to be able to remove by making the comment-value pair more transparent. The wrapper objects needs to work as dictionary keys, to support printing, concatenation/addition, getitem/setitem and such thin

Re: Wrapper objects

2004-12-10 Thread redhog
Ah, thanks. I didn't think of the possibility of creating a list of methods that needed wrapping, and wrapping them uppon creation of the wrapper object. Mainly I think, becaus it seems to me as such an uggly workaround for a misdesign in Python. Also, if the wrapped object gets some extra methods/

Re: Wrapper objects

2004-12-10 Thread Bengt Richter
On 10 Dec 2004 09:33:51 -0800, [EMAIL PROTECTED] wrote: >Bengt Richter wrote: >> On 9 Dec 2004 06:11:41 -0800, [EMAIL PROTECTED] (Egil M?ller) wrote: >> >> >So my naive implementation of a wrapper class, >> > >> > >> >class wrapper(object): >> >def __init__(self, value, otherdata): >> >

Re: Wrapper objects

2004-12-10 Thread redhog
Bengt Richter wrote: > On 9 Dec 2004 06:11:41 -0800, [EMAIL PROTECTED] (Egil M?ller) wrote: > > >Is there any way to create transparent wrapper objects in Python? > > > >I thought implementing __getattribute__ on either the wrapper class or > >its metaclass would do t

Re: Wrapper objects

2004-12-10 Thread Nick Coghlan
("Hi") .>>> x + " there!" __add__ 'Hi there!' .>>> "Wrapper says " + x __radd__ Traceback (most recent call last): File "", line 1, in ? File "wrapper.py", line 11, in __get__ return inst.__getattr__(self._name) File &

Re: Wrapper objects

2004-12-10 Thread Kent Johnson
Nick Coghlan wrote: Simon Brunning wrote: This work - ? Only for old-style classes, though. If you inherit from object or another builtin, that recipe fails. Could you explain, please? I thought __getattr__ worked the same with new-

Re: Wrapper objects

2004-12-10 Thread Nick Coghlan
Simon Brunning wrote: On 9 Dec 2004 06:11:41 -0800, Egil M?ller <[EMAIL PROTECTED]> wrote: Is there any way to create transparent wrapper objects in Python? This work - <http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52295>? Only for old-style classes, though. If you inherit

Re: Wrapper objects

2004-12-09 Thread Bengt Richter
On 9 Dec 2004 06:11:41 -0800, [EMAIL PROTECTED] (Egil M?ller) wrote: >Is there any way to create transparent wrapper objects in Python? > >I thought implementing __getattribute__ on either the wrapper class or >its metaclass would do the trick, but it does not work for the built &

Re: Wrapper objects

2004-12-09 Thread Simon Brunning
On 9 Dec 2004 06:11:41 -0800, Egil M?ller <[EMAIL PROTECTED]> wrote: > Is there any way to create transparent wrapper objects in Python? This work - <http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52295>? -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline

Wrapper objects

2004-12-09 Thread Egil M?ller
Is there any way to create transparent wrapper objects in Python? I thought implementing __getattribute__ on either the wrapper class or its metaclass would do the trick, but it does not work for the built in operators: class Foo(object): class __metaclass__(type): def