Re: Context manager with class methods

2011-09-23 Thread Gregory Ewing
Terry Reedy wrote: it is normal to look for special methods on the class (and superclasses) > of an object rather than starting with the object itself. I suspect there was a deliberate change to correct an anomaly, though this might have been done as part of some other change. It's a necess

Re: Context manager with class methods

2011-09-22 Thread Terry Reedy
On 9/22/2011 6:21 AM, Gavin Panella wrote: On Python 2.6 and 3.1 the following code works fine: class Foo(object): @classmethod def __enter__(cls): print("__enter__") @classmethod def __exit__(cls, exc_type, exc_value, traceback):

Re: Context manager with class methods

2011-09-22 Thread Mel
Mel wrote: > This seems to work: > > > > class MetaWith (type): > @classmethod > def __enter__(cls): > print("__enter__") > > @classmethod > def __exit__(cls, exc_type, exc_value, traceback): > print("__exit__") > > class With (object): > __metaclass__ = Met

Re: Context manager with class methods

2011-09-22 Thread Mel
Gavin Panella wrote: > Hi, > > On Python 2.6 and 3.1 the following code works fine: > > class Foo(object): > > @classmethod > def __enter__(cls): > print("__enter__") > > @classmethod > def __exit__(cls, exc_type, exc_value, traceback): >

Re: Context manager with class methods

2011-09-22 Thread Thomas Rachel
Am 22.09.2011 12:21 schrieb Gavin Panella: Hi, On Python 2.6 and 3.1 the following code works fine: class Foo(object): @classmethod def __enter__(cls): print("__enter__") @classmethod def __exit__(cls, exc_type, exc_value, traceback):

Context manager with class methods

2011-09-22 Thread Gavin Panella
Hi, On Python 2.6 and 3.1 the following code works fine: class Foo(object): @classmethod def __enter__(cls): print("__enter__") @classmethod def __exit__(cls, exc_type, exc_value, traceback): print("__exit__") with Foo