Tip:
Highlight text to annotate it
X
We're coming to the end of what I want to say about decorators.
I wanted to add one more debug tool.
That's one I'm going to call disabled.
It's very simple.
Disabled is another name for the identity function--
that is the function that returns its argument without doing any computation on it whatsoever.
Why do I want it and why do I call it "disabled?"
Well, the idea is that if I'm using some of these debugging tools like trace or countcalls,
I might have scattered throughout my program trace define f and some other traced functions.
Then I might decide I think I'm okay now. I think I've got it debugged.
I don't want to trace any more.
Then what I can do is I can just say "trace = disabled"
and reload my program, and now the decorator trace will be applied to the function,
but what it will do is return the function itself.
Notice we don't have to say that disabled is a decorator,
even though we're using it as if it were one,
because it doesn't create a new function. It just returns the original function.
That way we won't have the trace output cluttering up our output,
and the function will be efficient.
There won't even be a test to see if we are tracing or not.
It'll just use the exact function that passed in.