
On Aug 19, 2015, at 23:54, Thomas Güttler <guettliml@thomas-guettler.de> wrote:
I think it would be great to have properties for classes in Python2 and Python3
Well, Python 2 has been closed to new features for years now. Anyway, if you add a property to a metaclass, it does exactly what you want. (After all, a metaclass is the type of a class object, which is where you put class descriptors.)
There are some "patterns" to get this working:
http://stackoverflow.com/questions/5189699/how-can-i-make-a-class-property-i...
http://stackoverflow.com/questions/128573/using-property-on-classmethods
... but an official solution would be more "zen of python".
Do you think properties for classes would be useful?
If it works for classes, then it could be used for modules, too?
Modules are a more serious problem, because there's no immediate way to specify the type for a module object. You can work around it by, e.g., declaring a module subclass, copying the module's dict to an instance of that subclass, then replacing the entry in sys.modules, but this is more than a little ugly. There have been proposals to allow modules to specify a type (e.g., something similar to the way __metaclass__ worked in 2.x), and to make it easier to hook the import machinery to create modules of a custom type, and probably other variations on this. You might want to search this list and -dev for previous ideas, to find one you think should be reconsidered.
Regards, Thomas Güttler
PS: my first post via google groups web interface did not arrive here. That's the second try. Now via mail.
-- Thomas Guettler http://www.thomas-guettler.de/ _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/