Re: With class as contextmanager

2017-01-25 Thread This Wiederkehr
Thank you for your answers. Very appreciated. I ended up doing it as follows: class MetaLock(type): def __init__(cls, *args): super().__init__(*args) cls.lock = Lock() cls.instances = [] def register(cls, instance): cls.instances.append(instance) def

Re: With class as contextmanager

2017-01-24 Thread Terry Reedy
On 1/24/2017 4:31 PM, This Wiederkehr wrote: having a class definition: class Test(): @classmethod def __enter__(cls): pass @classmethod def __exit__(cls, exception_type, execption_value, callback): pass now using this as a contextmanager does not work, even though Test is an object

Re: With class as contextmanager

2017-01-24 Thread Ethan Furman
On 01/24/2017 02:35 PM, Ethan Furman wrote: On 01/24/2017 01:31 PM, This Wiederkehr wrote: having a class definition: class Test(): @classmethod def __enter__(cls): pass @classmethod def __exit__(cls, exception_type, execption_value, callback): pass now using this as a contextman

Re: With class as contextmanager

2017-01-24 Thread Ethan Furman
On 01/24/2017 01:31 PM, This Wiederkehr wrote: having a class definition: class Test(): @classmethod def __enter__(cls): pass @classmethod def __exit__(cls, exception_type, execption_value, callback): pass now using this as a contextmanager does not work, even though Test is an obj

Re: With class as contextmanager

2017-01-24 Thread Ian Kelly
On Tue, Jan 24, 2017 at 2:31 PM, This Wiederkehr wrote: > Hellou > > having a class definition: > > class Test(): > > @classmethod > def __enter__(cls): > pass > > @classmethod > def __exit__(cls, exception_type, execption_value, callback): > pass > > now using this as a contextmanager doe