[Python-Dev] More concerns about decorators (original) (raw)
Roman Suzi rnd at onego.ru
Mon Aug 16 17:39:54 CEST 2004
- Previous message: [Python-Dev] More concerns about decorators
- Next message: [Python-Dev] More concerns about decorators
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, 16 Aug 2004, Michael Hudson wrote:
Bob Ippolito <bob at redivi.com> writes:
Is it possible to change function inplace? Is it even an option? Not sure what you mean. Functions have a doc slot and a dict slot that are read/write. name is read-only. name is writable as of a few days ago.
I mean that decorators are... decorators. They by their meaning must not change the function but add some twists to their behaviour. Many of decorator examples are destructing function attributes.
Good example of non-destructing decorator is staticmethod:
class A: ... def m(x): ... """I am method m""" ... m.security = "low" ... m = staticmethod(m) ... A.m.doc 'I am method m' A.m.security 'low'
So, my concern was that it requires additional efforts to save function attributes. My thought was that probably decorators could work directly on the function, not changing id of the function? (staticmethod changes id, of course). Why? Because the function is not accessible any more. while the old way it was possible to store intermediate result:
class A: def m(x): """I am method m""" mm = m m = staticmethod(m)
And use it somehow. But with decorator function changes. Yes, it is possible that some decorators could store function internally for the purpose of calling it, but others will not.
The transfer of function attributes is on the developer. And he/she could be clueless that docstrings, etc, could be lost in transformation.
Sincerely yours, Roman Suzi
rnd at onego.ru == My AI powered by GNU/Linux RedHat 7.3
- Previous message: [Python-Dev] More concerns about decorators
- Next message: [Python-Dev] More concerns about decorators
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]