[Python-Dev] PEP 549: Instance Properties (aka: module properties)
Guido van Rossum
guido at python.org
Wed Sep 13 19:13:57 EDT 2017
On Wed, Sep 13, 2017 at 3:01 PM, Ivan Levkivskyi <levkivskyi at gmail.com>
> > One would have to introduce some kind of convention
> > where you can write properties with a leading _
> One doesn't even need the @property decorator in this case.
> For example:
> def __getattr__(name):
> g = globals()
> name = '_' + name
> if name in g:
> return g[name]()
> raise AttributeError(...)
> def _attr():
> "do something"
> return actual_object
> One can even write a decorator that would change the name automatically
> (but this will require a call at the end of module to unbind original
> The space for play is infinite. The question is what exactly is needed.
> I would say that already basic customisation (like __getattr__) will be
> IIUC, this will be actually a bit faster than setting __class__ since only
> attributes will be affected.
That last sentence is a key observation. Do we even know whether there are
(non-toy) things that you can do *in principle* with __class__ assignment
but which are too slow *in practice* to bother? And if yes, is __getattr__
fast enough? @property?
IMO we're still looking for applications.
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev