* tweak adding attributes example

* add open issue about changing func_name
This commit is contained in:
Skip Montanaro 2004-03-31 18:19:22 +00:00
parent 8eb5243bfe
commit ad298dbac2
1 changed files with 13 additions and 6 deletions

View File

@ -247,23 +247,25 @@ some examples of use.
class MyClass [singleton]:
...
3. Decorate a function with release information. (Based on an example
posted by Anders Munch on ``python-dev``.)
3. Add attributes to a function. (Based on an example posted by
Anders Munch on ``python-dev``.)
::
def release(**kwds):
def attrs(**kwds):
def decorate(f):
for k in kwds:
setattr(f, k, kwds[k])
return f
return decorate
def mymethod(f) [release(versionadded="2.2",
author="Guido van Rossum")]:
def mymethod(f) [attrs(versionadded="2.2",
author="Guido van Rossum")]:
...
4. Enforce function argument and return types.
4. Enforce function argument and return types. (Note that this is not
exactly correct, as the returned new_f doesn't have "func" as its
func_name attribute.)
::
@ -330,6 +332,11 @@ Open Issues
(search for ``PEP 318 - posting draft``) on their behalf in
``python-dev``.
2. Decorators which wrap a function and return a different function
should be able to easily change the func_name attribute without
constructing it with new.function(). Perhaps the func_name
attribute should be writable.
.. _strong arguments:
http://mail.python.org/pipermail/python-dev/2004-March/thread.html