[Python-Dev] syntax for funcion attributes
Michael Hudson
mwh@python.net
Sat, 01 Mar 2003 11:12:21 +0000
"Mark Nottingham" <mnot@mnot.net> writes:
> Hello,
>
> I'm not a python-dev regular, so sorry if this is a FAQ. What's the status
> of defining a syntax for function attributes (PEP 232)?
I don't think changes here are likely.
> I'm using __doc__ to carry metadata about methods right now, but
> would very much like to use function attributes. However, without a
> specialized syntax, I'm stuck doing things like
>
> VeryLongMethodName.MetadataName = "foo"
>
> which is fine if it's a one-off, but I'd like others to use the code, and
> this isn't exactly a friendly mechanism.
If PEP <the one I haven't written yet> gets accepted, you'll be able
to do
def with_metadata(func):
func.metadata = "yes"
def f(blah) [with_metadata]:
....
or even
def with_metadata(data):
def inner(func):
func.metadata = data
return inner
def f(blah) [with_metadata("yes")]:
....
Would that suit you?
Cheers,
M.
--
> Why are we talking about bricks and concrete in a lisp newsgroup?
After long experiment it was found preferable to talking about why
Lisp is slower than C++...
-- Duane Rettig & Tim Bradshaw, comp.lang.lisp