On Wed, Aug 10, 2016 at 4:43 AM, Giampaolo Rodola' wrote:
> Chris' SimplerContextManager solution is faster because it avoids the
> factory function but that is necessary for supporting the decoration of
> methods.
Hooking a tangent onto this: I have no idea, based on the current
source code, whi
On 10 August 2016 at 04:43, Giampaolo Rodola' wrote:
>
>
> On Tue, Aug 9, 2016 at 3:30 PM, Nick Coghlan wrote:
>
>> On 9 August 2016 at 23:26, Nick Coghlan wrote:
>>
>>> On 9 August 2016 at 06:18, Guido van Rossum wrote:
>>>
I think Nick would be interested in understanding why this is th
On 09.08.16 00:59, Chris Angelico wrote:
class TooSimpleContextManager:
"""Now this time you've gone too far."""
def __init__(self, func):
self.func = func
def __call__(self):
self.gen = self.func()
return self
def __enter__(self):
next(self.gen)
On Wed, Aug 10, 2016 at 4:43 AM, Giampaolo Rodola' wrote:
> -return self.__class__(self.func, self.args, self.kwds)
> +func, args, kwds = self.funcak
> +return self.__class__(func, args, kwds)
return self.__class__(*self.funcak)
> @wraps(func)
> def helper(*args
On Tue, Aug 9, 2016 at 3:30 PM, Nick Coghlan wrote:
> On 9 August 2016 at 23:26, Nick Coghlan wrote:
>
>> On 9 August 2016 at 06:18, Guido van Rossum wrote:
>>
>>> I think Nick would be interested in understanding why this is the case.
>>> What does the decorator do that could be so expensive?
On Mon, Aug 8, 2016 at 11:59 PM, Chris Angelico wrote:
> On Tue, Aug 9, 2016 at 7:14 AM, Wolfgang Maier
> wrote:
> > Right, I think a fairer comparison would be to:
> >
> > class ctx2:
> > def __enter__(self):
> > self.it = iter(self)
> > return next(self.it)
> >
> > def
On 9 August 2016 at 23:26, Nick Coghlan wrote:
> On 9 August 2016 at 06:18, Guido van Rossum wrote:
>
>> I think Nick would be interested in understanding why this is the case.
>> What does the decorator do that could be so expensive?
>>
>
> Reviewing https://hg.python.org/cpython/file/default/L
On 9 August 2016 at 06:18, Guido van Rossum wrote:
> I think Nick would be interested in understanding why this is the case.
> What does the decorator do that could be so expensive?
>
Reviewing https://hg.python.org/cpython/file/default/Lib/contextlib.py#l57,
Chris's analysis seems plausible to
On Tue, Aug 9, 2016 at 7:14 AM, Wolfgang Maier
wrote:
> Right, I think a fairer comparison would be to:
>
> class ctx2:
> def __enter__(self):
> self.it = iter(self)
> return next(self.it)
>
> def __exit__(self, *args):
> try:
> next(self.it)
> e
On 8/8/2016 22:38, Yury Selivanov wrote:
On 2016-08-08 4:18 PM, Guido van Rossum wrote:
I think Nick would be interested in understanding why this is the
case. What does the decorator do that could be so expensive?
From the looks of it it doesn't do anything special. Although with
@contextl
On 2016-08-08 4:18 PM, Guido van Rossum wrote:
I think Nick would be interested in understanding why this is the
case. What does the decorator do that could be so expensive?
From the looks of it it doesn't do anything special. Although with
@contextlib.contextmanager we have to instantiate
On Mon, Aug 8, 2016 at 10:07 PM, Yury Selivanov
wrote:
>
>
> On 2016-08-08 3:33 PM, Giampaolo Rodola' wrote:
>
>> I wanted to give it a try rewriting this in C but since @contextmanager
>> has a lot of magic I wanted to ask first whether this 1) is technically
>> possible 2) is desirable.
>>
>
>
I think Nick would be interested in understanding why this is the case.
What does the decorator do that could be so expensive?
On Mon, Aug 8, 2016 at 1:07 PM, Yury Selivanov
wrote:
>
>
> On 2016-08-08 3:33 PM, Giampaolo Rodola' wrote:
>
>> I wanted to give it a try rewriting this in C but since
On 2016-08-08 3:33 PM, Giampaolo Rodola' wrote:
I wanted to give it a try rewriting this in C but since
@contextmanager has a lot of magic I wanted to ask first whether this
1) is technically possible 2) is desirable.
It is definitely technologically possible. However, the C
implementation
import timeit
import contextlib
@contextlib.contextmanager
def ctx1():
yield
class ctx2:
def __enter__(self):
pass
def __exit__(self, *args):
pass
t1 = timeit.timeit("with ctx1(): pass", setup="from __main__ import ctx1")
t2 = timeit.timeit("with ctx2(): pass", setup=
15 matches
Mail list logo