[Python-ideas] C# style properties

Neil Toronto ntoronto at cs.byu.edu
Sat Jul 14 06:54:11 CEST 2007

Greg Ewing wrote:
> Neil Toronto wrote:
>  > 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):
>        ...

Surely you meant to write "instance". :) I like that spelling. The 
keyword has exactly the right meaning. I imagine having to create a new 
keyword just for a bit of syntactic sugar would be the main argument 
against it.

It's not just about saving keystrokes, though.

> which would be roughly equivalent to
>    class _foo(property):
>      ...
>    foo = _foo()
> but without the intermediate class name.

Seems this sort of thing would be trivial with a class decorator, 
something like "@instance" or "@oneinstance". ("@singleton" would 
probably make people expect a call to the class to return a unique 
instance only the first time.) As part of my new delvination (that's a 
word) into metaclasses, I've been trying to make a metaclass that does 
the same thing. (No spoilers, please!)


More information about the Python-ideas mailing list