[Python-Dev] Property syntax

Oren Tirosh oren-py-d@hishome.net
Mon, 3 Feb 2003 01:34:52 +0200


On Sun, Feb 02, 2003 at 02:17:22PM -0500, Guido van Rossum wrote:
> Um, I thought this was going on on python-dev?  This is way too raw
> for c.l.py.  

Oops. I added CC manually and typed python-list instead of python-dev.

> Given that the syntax for a class's bases and for a function's
> arguments are completely different and incompatible, I'm not sure how
> you can ever come up with a construct that unifies them.

Dunno. Let's try.


    def F():
        suite
<=>
    def F as function: 
        suite
<=>
    F = function(CODE, globals(), 'F')


    class C(X, Y):
        suite
<=>
    def C as type:	
        __bases__ = X, Y
        suite
<=>
    C = type(CODE, globals(), 'C')   # where CODE assigns to __bases__


    def F(arg=defaultvalue):
        suite
<=>
    #def F as function: 
    #    no suite can create a code object with co_argcount != 0
    #    It can't return or yield either. Only def with parens can 
    #    create a code object with these features.
<=>
    F = function(CODE, globals(), 'F', (defaultvalue,))


    def static() as staticmethod:
<=>
    def static as function, staticmethod:
<=>
    static = staticmethod(function(CODE, globals(), 'F'))


    def foo as property:
        def __get__(self):
            ...
        def __set__(self):
<=>
    foo = property(CODE, globals(), 'foo') 
    # execs CODE in a dict, reads __get__, __set__, __del__ items from it

> And where did pypy-dev come from?  I thought that the
> point of pypy-dev was not to invent new language constructs?

Looking this way at the creation of function object and class objects 
may help in implementing them in pure Python. There is no need for a 
dedicated bytecode - 'def' and 'class' are just a different way to 
write the constructor calls above. 

    Oren