[Python-ideas] adding an __exec__ method to context managers?

Carl Johnson cmjohnson.mailinglist at gmail.com
Wed Oct 14 10:49:57 CEST 2009


Terry Reedy:
> Carl Johnson wrote:
>
>> Why? Because it's more readable to have the decorator up top, so you
>> know what kind of function/method to expect.
>
> Part of the motivation for @ you are missing was the desire to not write
>  the function name three times, especially when the name is long, as is
> required in some contexts where functions must be wrapped to interface with
> external systems. The classmethod use case alone would not have pushed the
> addition.

Yes, but if we go from using def to make a function and then giving
that as a callback to using a multiline lambda, that's a drop from
using the function name 2 times to using it 0 times: the same
magnitude of a drop: -2 ! ;-D

(Of course, I'm only mentioning this in jest, since multiline lambdas
are unpythonic. I just wanted to point out that it's the same
reduction in typing.)

-- Carl



More information about the Python-ideas mailing list