doctests and decorators
Scott David Daniels
Scott.Daniels at Acm.Org
Tue Jun 16 15:04:32 EDT 2009
Eric Snow wrote:
> In general should decorators always hide themselves? I am guessing
> not, otherwise this would already be part of their behavior. Still,
> is it the common case to camouflage the decorator like this? If so, I
> would expect it to be the default behavior of decorators.
The Python goal is "no magic". So, if you want the stuff wrapped, you
do it (as the default traceback shows where the code actually goes).
It would be far more complicated to display the truth if decorators
defaulted to modifying the builtins, and you had to do magic to remove
that part of the decoration. A decorator has _very_ simple semantics,
while anything that automatically copied attributes would have funny
semantics indeed for use by funny decorators like:
abi = []
def indexed(function):
result = len(abi)
abi.append(function)
return result
@indexed
def first_function(...):
...
@indexed
def second_function(...):
...
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list