[Python-Dev] Keyword for block statements

Nick Coghlan ncoghlan at gmail.com
Sun May 1 14:24:57 CEST 2005


Ka-Ping Yee wrote:
> The programmer who writes the function used to introduce a block
> can hardly be relied upon to explain the language semantics.  We
> don't expect the docstring of every class to repeat an explanation
> of Python classes, for example.  The language reference manual is
> for that; it's a different level of documentation.

Would 'suite' work as the keyword?

Calling these things 'suite' statements would match the Python grammar, give an 
obvious visual indicator through the use of a keyword, reduce any confusion 
resulting from the differences between Python suites and Ruby blocks (since the 
names would now be different), and avoid confusion due to the multiple meanings 
of the word 'block'.

And really, what PEP 340 creates is the ability to have user-defined suites to 
complement the standard control structures.

Anyway, here's the examples from the PEP using 'suite' as the keyword:

         suite synchronized(myLock):
             # Code here executes with myLock held.  The lock is
             # guaranteed to be released when the block is left (even
             # if by an uncaught exception).

         suite opening("/etc/passwd") as f:
             for line in f:
                 print line.rstrip()

         suite transactional(db):
             # Perform database operation inside transaction

         suite auto_retry(3, IOError):
             f = urllib.urlopen("http://python.org/peps/pep-0340.html")
	    print f.read()

         suite synchronized_opening("/etc/passwd", myLock) as f:
             for line in f:
                 print line.rstrip()

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net


More information about the Python-Dev mailing list