[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

newb question about @property

Chris Angelico <rosuav at gmail.com>:

> Yes, that's correct. The *descriptor* protocol is what allows
> "foo.bar" to cause a function to be executed

That mechanism allows you to expose data fields in the API. If the
implementation later changes, you can emulate the data fields.

I must say, though, I have yet to run into a need for descriptors.

> the *decorator* protocol is what lets you "tag" a function:

i have yet to need that, either. I have *seen* a semi-useful decorator
in code once (@contextlib.contextmanager) but still would prefer
explicit dunder methods.