Python becoming less Lisp-like

Paul Boddie paul at
Thu Mar 17 09:57:15 CET 2005

"Kay Schluehr" <kay.schluehr at> wrote in message news:<1110999333.028296.319800 at>...
> Some people refused properties in Python for exactly this reason.
> Defining somewhat like:
> def _get_X(self):
>     return self._X
> def _set_X(self,X):
>     self._X =3D X
> X =3D property(_get_X, _set_X )
> in a Java-style fashion is indeed awfull and clumsy and that people
> dismiss such boilerplate code is understandable.

The principal advantage of the property function was to permit the
definition of "active" attributes without having a huge
"if...elif...else" statement in the __getattr__ method. So the
motivation was seemingly to externalize the usually simple logic in
__getattr__ so that one could know a bit more about the supported
properties of an object without having to read the source code.

Java should be able to support Python-style properties by converting
property accesses to accessor method calls before runtime, but with
this capability within easy reach (and in all irony), the creators of
the language instead decided to force programmers to explicitly call
these rigidly-named methods, despite the raw property names actually
being exposed to external tools like property editors, JavaServer
Pages, and so on.

[accessor code cut]

> class X(object):
>     a = accessor("a")
>     b = accessor("b", types = (tuple,list))
>     c = accessor("c", check = lambda x:hasattr(x,"__len__"))

Hmmm, lambda!

> a,b,c are indeed properties of X !
> >>> x = X()
> >>> x.b = [1,2,3] # o.k
> >>> x.b
> [1, 2, 3]
> >>> x.b = 0  # raises a TypeError, because a tuple/list is expected

This is a nice example, but I do wonder why so many examples of
Python's dynamicity, especially with many of the newer features, seek
to provide static type checking or some other variant on that theme.
It would be nice to see more work done at the level of the compiler to
achieve those kinds of goals.

    Who would cross the Bridge of Death must answer me these
    questions three, ere the other side he see.
    Ask me the questions, bridgekeeper. I am not afraid.
    What... is your name?
    My name is 'The Pythonic Knight'.
    What... is your quest?
    To seek the Holy Grail.
    What... are decorators for?
    Static type checking. No, param-- auuuuuuuugh!

Or something [1] like that.



More information about the Python-list mailing list