On 2016-05-10 17:06, Stephen Hansen wrote:
On Tue, May 10, 2016, at 08:45 AM, Steven D'Aprano wrote:
I have a decorator that adds an attribute to the decorated function:
[...]
My question is, what should I do if the decorated function already has an
instrument attribute?

1. raise an exception?

This. Your decorator should, IMHO, treat the attribute as private data,
and if something else is using the same thing, something has clearly
gone wrong and raising the error early and clearly is right.

If it's not clear what you should do, you could look at the Zen. It says: "In the face of ambiguity, refuse the temptation to guess." To me, that suggests raising an exception.

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to