[Python-Dev] [PEP 232] Syntactic support for function attributes strawman.

Michael Hudson mwh21@cam.ac.uk
26 Jan 2001 16:40:47 +0000


Following discussion on c.l.py I've just submitted:

http://sourceforge.net/patch/?func=detailpatch&patch_id=103441&group_id=5470

which implements a syntax for adding function attributes inline:

>>> def f(a) having (publish=1):
...  print 1
... 
>>> f.publish
1

It uses an "import-as" like strategy to avoid makeing "having" a
keyword (which interacts a bit badly with error reporting, as it
happens).  Obviously, it would be easy to change "having" to a
different word.

Another idea I had was:

>>> def f(a) having (.publish=1):
...  print 1
... 
>>> f.publish
1

to emphasize the attributeness of what's going on, but I didn't like
this as much in practice (I always forgot the period!).

Emile van Sebille also suggested

>>> d = {'a':1}
>>> def f(a) having (**d):
...  print 1
... 
>>> f.a
1

which I haven't implemented, because I didn't really like it, but I
thought I'd mention.

I'll do test suites and documentation in time, but I thought I'd call
in here to check the idea wasn't DOA.  What do you all think?

Cheers,
M.

-- 
  surely, somewhere, somehow, in the history of computing, at least
  one manual has been written that you could at least remotely
  attempt to consider possibly glancing at.              -- Adam Rixey