* tweak adding attributes example
* add open issue about changing func_name
This commit is contained in:
parent
8eb5243bfe
commit
ad298dbac2
19
pep-0318.txt
19
pep-0318.txt
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue