[Python-Dev] Wrappers and keywords

"Martin v. L÷wis" martin@v.loewis.de
Thu, 17 Apr 2003 22:12:19 +0200


David LeBlanc wrote:
> I am curious to know why the, what seems to me kludgy, "def x(): pass  x =
> (static|class)method(x)" syntax was chosen over a simple "staticdef x
> ():..." or "classdef x ():..." def specialization syntax? 

That syntax hasn't been chosen yet; syntactic sugar for static and class
methods, properties, slots, and other object types is still an area of
ongoing research.

The current implementation was created since it did not need an 
extension to the syntax:

    x=staticmethod(x)

was syntactically correct even in Python 1.2 (which is the oldest
Python version I remember).

There have been numerous proposals on what the syntactic sugar should
look like, which is one reason why no specific solution has been 
implemented yet. Proposals get usually discredit if they require 
introduction of new keywords, like "staticdef". The current favorite 
proposals is to write

   def x() [static]:
     pass

or perhaps

   def x() [staticmethod]:
     pass

In that proposal, static(method) would *not* be a keyword, but would
be an identifier (denoting the same thing that staticmethod currently 
denotes). This syntax nicely extends to

   def x() [threading.synchronized, xmlrpclib.webmethod]:
     pass

The syntax has the disadvantage of not applying nicely to slots.

Regards,
Martin