Possible PEP: Improve classmethod/staticmethod syntax

Sean Ross frobozz_electric at hotmail.com
Wed Jun 4 10:55:05 EDT 2003


"Gerrit Holl" <gerrit at nl.linux.org> wrote in message
news:mailman.1054718112.3943.python-list at python.org...
>
> I don't see how properties would fit into any of these syntaxes
> though, because the property() function takes multiple arguments.
>


Perhaps you would have something like the following:

def foo(self) [property]:
    "here's the properties doc string"
    def get():
        return self.__foo
    def set(value):
        self.__foo = value
    def del():
        del self.__foo

Where the property attribute would signal the interpreter to look for nested
functions 'get', 'set', and possibly 'del'. You would only be required to
define the methods you want, but they would have to follow this form. So,
for instance, creating a read-only property could look something like this:

def bar(self)[property]:
    def get():
        return self.__bar


Just a thought.

Personally, I would like to see something like this:

def foo(self) as property:
    def get():
        ...
    ...

def Frobozz() as static:
    ...

def eiffel(self) as contract(pre=pre, post=post):
    ...

def ManyFunctionAttributes() as static, contract(pre,post):
     ...

and

def ClassName.methodname():
    "a class method"
    ...


Perhaps static methods should look more like class methods:

def ClassName.methodname() as static:
    ...

I don't know...just some ideas...









More information about the Python-list mailing list