python-2.1 function attributes

Michael Hudson mwh21 at cam.ac.uk
Thu Jan 25 15:47:32 EST 2001


barry at digicool.com (Barry A. Warsaw) writes:

> >>>>> "MH" == Michael Hudson <mwh21 at cam.ac.uk> writes:
> 
>     MH> I suspect if you can come up with a decent syntax, it will go
>     MH> in.  I can't though.  Any ideas?
> 
> That's definitely been the problem so far.  Function attribute tend to
> be very useful even without the syntax, but I think many people agree
> that an inline syntax a la docstrings would make the feature even more
> useful.  So far, no one's come up with an acceptable syntax.  My
> inclination would be to open a new PEP for just the syntax proposal,
> referencing PEP 232 for the underlying implementation and access
> rules.

Ooh, I've come up with a strawman!

One concrete idea: lose the dict analogy.  It's only an implementation
detail, and being able to have attributes whose names aren't strings
is bonkers.  The nearest equivalent in contemporary Python is the
class statement, let's ape that.

Now some ideas:

def f(a, b, c)
 .publish = 1
 .secure = 0:
    print "bobbins"

Don't really like having the colon-free indent.

def f(a, b, c) with:
  publish = 1
  secure = 0:
    print "bobbins"

I think this is my favourite that I've seen yet.  Should be done with
an "as"-like hack to avoid making is a keyword.  The double indent is
a bit naff, but I can't see a way of clearly distinguishing attributes
from code without something like that.

Maybe a variant:

def f(a, b, c) with publish = 1; secure = 0:
    print "bobbins"

Then you use backslashes when the attribute or argument list get long.

def f(long_name, even_longer_name, still_longer_name) \
        with publish = 1; secure = 0
             grammar = f_grammar:
    print "bobbins"

Thoughts?

Cheers,
M.

-- 
  This is an off-the-top-of-the-head-and-not-quite-sober suggestion,
  so is probably technically laughable.  I'll see how embarassed I
  feel tomorrow morning.            -- Patrick Gosling, ucam.comp.misc



More information about the Python-list mailing list