Function metadata (like Java annotations) in Python
oripel
oripel at gmail.com
Sun Sep 10 08:27:11 EDT 2006
Thanks bearophile,
I prefer not to use docstrings for metadata.
1. Not interfering with the other accepted docstring uses may be
difficult (doctests, epydoc)
2. It's impractical for attributes generated by code:
@attr(reference_profile_stats=pstats.Stats("foo.profile"))
def foo():
...
Regards,
Ori.
bearophileHUGS at lycos.com wrote:
> oripel:
>
> Maybe this is a silly suggestion, the docstring is already overloaded,
> but it may be used for this too:
>
> def foo():
> """
> ...
> ...
> @ATTR name="Xander"
> @ATTR age=10
> @ATTR hobby="knitting"
> """
> ...
>
> (Or somethins similar without the @). Later you can retrive the
> attributes from the docstring, for example using a verbose RE like:
> r"\s* @ATTR \s+ (\w*) \s* = \s* (.*)"
> And you use it to create a dict of attributes.
> The decorators you apply to foo() must keep its docstring too.
>
> Bye,
> bearophile
More information about the Python-list
mailing list