PEP 343, second look

Ron Adam rrr at ronadam.com
Wed Jun 22 17:50:43 EDT 2005


Paul Rubin wrote:
> Ron Adam <rrr at ronadam.com> writes:
> 
>>>A new statement is proposed with the syntax:
>>>        with EXPR as VAR:
>>>            BLOCK
>>>    Here, 'with' and 'as' are new keywords; EXPR is an arbitrary
>>>    expression (but not an expression-list)...
>>
>>How is EXPR arbitrary?  Doesn't it need to be or return an object that
>>the 'with' statement can use?  (a "with" object with an __enter__ and
>>__exit__ method?)
> 
> 
> That's not a syntactic issue.  "x / y" is a syntactically valid
> expression even though y==0 results in in a runtime error.

The term 'arbitrary' may be overly broad.  Take for example the 
description used in the 2.41 documents for the 'for' statement.

"The expression list is evaluated once; it should yield an iterable object."


If the same style is used for the with statement it would read.

"The expression, (but not an expression-list), is evaluated once; it 
should yield an object suitable for use with the 'with' statement. ... "

Or some variation of this.


Regards,
Ron









More information about the Python-list mailing list