[Python-Dev] #pragmas and method attributes

M.-A. Lemburg mal@lemburg.com
Wed, 12 Apr 2000 21:02:25 +0200


Moshe Zadka wrote:
> 
> On Wed, 12 Apr 2000, Paul Prescod wrote:
> 
> > About a month ago I wrote (but did not publish) a proposal that combined
> > #pragmas and method attributes. The reason I combined them is that in a
> > lot of cases method "attributes" are supposed to be available in the
> > parse tree, before the program begins to run. Here is my rough draft.
> 
> FWIW, I really really like this.
> 
> def func(...):
>         decl {zorb: 'visible', spark: 'some grammar rule'}
>         pass
> 
> Right on!
> 
> But maybe even
> 
> def func(...):
>         decl zorb='visible'
>         decl spark='some grammar rule'
>         pass

Hmm, this is not so far away from simply letting function/method
attribute use the compiled-in names of all locals as basis, e.g.

def func(x):
    a = 3

print func.a

func.a would look up 'a' in func.func_code.co_names and return
the corresponding value found in func.func_code.co_consts.

Note that subsequent other assignments to 'a' are not recognized
by this technique, since co_consts and co_names are written
sequentially. For the same reason, writing things like 'a = 2 + 3'
will break this lookup technique.

This would eliminate any need for added keywords and probably
provide the best programming comfort and the attributes
are immutable per se.

We would still have to come up with a way to declare these
attributes for builtin methods and modules...

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/