[Python-ideas] C# style properties

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Jul 14 04:58:46 CEST 2007


Neil Toronto wrote:
> Inner-class-as-a-class-variable is the 
> mental leap you have to make, plus you have to be comfortable with 
> metaclasses.

Actually, I think there's a further mental leap you have
to make -- the notion that a 'class' statement can create
something that is *not* a class. Just knowing that there
is a metaclass involved is not enough to alert you to
this possibility.

IMO this is something that should definitely not be
encouraged, as it directly obfuscates the code --
you're saying 'class' when you don't really mean it.

 > It might be nice to be able
 > to declare a one-off namespace:

Yes, things like this have been suggested before.
There was a thread not long ago about a 'make'
statement, for example, and there have been numerous
suggestions for a 'namespace' statement.

My favourite version would be something like

   intance foo(property):

     def __get__(self):
       ...

     def __set__(self, x):
       ...

which would be roughly equivalent to

   class _foo(property):
     ...

   foo = _foo()

but without the intermediate class name.

--
Greg



More information about the Python-ideas mailing list