Syntax modification idea: (classmethods, properties locking...)
jepler at unpythonic.net
Thu Jan 16 23:37:07 CET 2003
On Thu, Jan 16, 2003 at 10:03:12PM +0100, Arne Koewing wrote:
> After reading some treads about
> "A Hygienic Macro System in Python"
> i've had an idea:
> why not extending the def statement?
> class bar(object):
> def foo(class,arg1) is classmethod:
> def bar(arg1) is staticmethod:
> def X(...) is Y: #don't know if 'is' is realy a goog idea...
Something like this was suggested once, possibly on python-dev. The
syntax proposed there was:
def f() [classmethod]:
A chained form was also proposed.
The proposal did not win any wide acceptance.
I also wonder if trick used to make 'import ... as' legal without making
'as' a keyword could work in this situation, as in:
funcdef: 'def' NAME NAME? parameters ':' suite
If the second NAME is present, then it is the name of the function and
the first NAME is the function's transformer. This could be applied to
classes as well:
classdef: 'class' NAME NAME? ['(' testlist ')'] ':' suite
if both names are specified, then the first is the metaclass. Examples
(assuming an appropriate definition of the memoized wrapper & singleton
# Equivalent to
# class S:
# __metaclass__ = singleton
class singleton S: ...
# Equivalent to
# def f(x): ...
# f = memoized(f)
def memoized f(x): ...
lowercase 'singleton' looks better to me than the alternative, 'class
Singleton S', same for 'memoized' vs 'Memoized'.
However, in this proposal, the following can't work
def locked_with("resource") f(x): ...
you're forced to do
locked_with_resource = locked_with("resource")
def locked_with_resource f(x): ...
instead. Also, no chained form is possible.
More information about the Python-list