[Python-Dev] PEP 318: what C# does

Paul Prescod paul at prescod.net
Thu Feb 26 05:47:12 EST 2004


Here's what C# does:

[System.Xml.Serialization.XmlRootAttribute("bookstore", Namespace="", 
IsNullable=false)]
public class bookstoreType {
  ....
     [System.Xml.Serialization.XmlElementAttribute("book")]
     public bookType[] book;

}

One thing to note is that C# allows the wrapping of attributes, not just 
functions and classes.

In Python this could be accomplished if we used delimiters that didn't 
look like lists (e.g. <> or [! !]).

C# distinguishes between bareword declarations like "public" and "int" 
and metadata attachments like XML serialization information.

I feel like there is a similar distinction lurking in the Python world. 
"staticmethod" says that the thing _is_ a static method. It changes the 
calling convention for that function.

Whereas a "public" or "ZopePublish" attribute is pure metadata. It 
doesn't change the way you call the function, just who can call it. We 
could combine the C# idea with the bareword idea like so:

  <synchronized(lock),
    ZopePublish,
    protected,
    SparkGrammar("x := y z"),
    win32com_return_type(int),
    win32com_public>
def staticmethod x():
	...

Statements cannot start with "<" so there is no ambiguity about the 
meaning of the character in this context.

  Paul Prescod





More information about the Python-Dev mailing list