[Python-Dev] Re: PEP 318: Decorators last before colon (original) (raw)
Neil Schemenauer nas-python at python.ca
Wed Mar 31 19:39:13 EST 2004
- Previous message: [Python-Dev] Re: PEP 318: Decorators last before colon
- Next message: [Python-Dev] Re: PEP 318: Decorators last before colon
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, Mar 31, 2004 at 07:16:06PM -0500, Phillip J. Eby wrote:
It sounds like a lot of people's "use" translates to your "abuse"; e.g. Bob's use cases would certainly have to be considered abuse, since they wouldn't be part of some fixed set defined by Python.
Yup. It seems to me that there are a number of different use cases and they all want to try to use the same new syntax.
[Binding to the last function definition] doesn't do what's needed, since you left out the rebinding of the function name.
That's possible without new syntax. Some example code:
import sys
def myclassmethod(func):
frame = sys._getframe(1)
name = func.func_name
if name in frame.f_locals:
namespace = frame.f_locals
elif name in frame.f_globals:
namespace = frame.f_globals
else:
raise NameError, 'cannot find %r' % name
namespace[name] = classmethod(func)
class A:
def something():
pass
myclassmethod(something)
print something
It's not pretty but it might prevent people from developing RSI while Guido works out what new syntax is best.
Finally, it doesn't address the issue of wanting to call these things out ahead of the function's code, as part of the definition header, so that a person who is reading for an overview can notice it and take it in.
That's true.
Neil
- Previous message: [Python-Dev] Re: PEP 318: Decorators last before colon
- Next message: [Python-Dev] Re: PEP 318: Decorators last before colon
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]