[Python-Dev] [Python 2.2 BUG] pickle/cPickle does not find slots (original) (raw)
Burton Radons loth@users.sourceforge.net
Fri, 15 Feb 2002 17:05:00 -0800
- Previous message: [Python-Dev] property syntax
- Next message: [Python-Dev] [Python 2.2 BUG] pickle/cPickle does not find
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Fred L. Drake, Jr. wrote:
Michael McLay writes: > While my approach was patterened after the property() builtin, the > Python Labs crowd didn't like the notation and rejected the
I'll note as well that at least some of us, if not all, don't like the property() syntax as well. My current favorite was one of Guido's proposals at Python 10:
class Foo(object): property myprop: """A computed property on Foo objects.""" def get(self): return ... def set(self): ... def delete(self): ...
What's wrong with:
class Foo(object): class myprop_class (object): """A computed property on Foo objects."""
def __get__(subclass, self, klass):
return ...
def __set__(subclass, self, value):
...
def __delete__(subclass, self):
...
myprop = myprop_class ()
It's a grand total of two lines more than your example, and has more extensions possibilities to boot.
While we're discussing strange usages of blocks, one feature I've always wanted has been subblocks passed to functions. It could be done using a new argument prefix "@" (for example). If the block is not otherwise taken (if it is in an if statement, for example), it can be followed by ":" and a normal block; this block is then put in the argument as a PyCodeObject (I think). The argument can also be given a value normally. The code object also has a few new methods for our convenience.
So to implement your example above:
def field (@block): dict = block.exec_save_locals () # Execute the block and return the locals dictionary rather than destroy it. fget = dict.get ("get", None) fset = dict.get ("set", None) fdel = dict.get ("delete", None) fdoc = dict.get ("doc", None)
return property (fget, fset, fdel, fdoc)
Now that we have that, we do your example:
class Foo(object): myprop = field (): """A computed property on Foo objects."""
def __get__(self):
return ...
def __set__(self, value):
...
def __delete__(self):
...
There are other capabilities, but as I've never had a language that can do this I wouldn't know how many pragmatic possibilities there are. The advantage over Guido's method is that his suggestion solves a single problem and has no use outside of it, while mine, at least on the face of it, could be applied in other ways.
- Previous message: [Python-Dev] property syntax
- Next message: [Python-Dev] [Python 2.2 BUG] pickle/cPickle does not find
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]