newb question about @property

Thomas Jollans tjol at tjol.eu
Mon Oct 2 05:46:23 EDT 2017


On 2017-10-02 10:51, Marko Rauhamaa wrote:
> Chris Angelico <rosuav at gmail.com>:
> 
>> On Mon, Oct 2, 2017 at 5:34 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
>>> I have *seen* a semi-useful decorator in code once
>>> (@contextlib.contextmanager) but still would prefer explicit dunder
>>> methods.
>>
>> [...] I'm not sure where dunder methods come into this, though, as
>> they're completely unrelated.
> 
> A context manager must implement __enter__() and __exit__().
> @contextlib.contextmanager implements them for you.

Let's revisit the bit of Chris' mail you didn't quote:

On 2017-10-02 09:02, Chris Angelico wrote:
>
> There are plenty of programs that don't need decorators, but in some
> contexts, they are just beautiful. Building a web app in Flask or
> Django involves functions that get decorated to say what endpoints
> they handle, for instance.

The point is that there are plenty of useful decorators that have
nothing to do with dunder methods.


-- 
Thomas Jollans



More information about the Python-list mailing list