Nick Coghlan wrote:
 >Anders J. Munch wrote:
 >
 >>Note that __with__ and __enter__ could be combined into one with no
 >>loss of functionality:
 >>
 >>        abc,VAR = (EXPR).__with__()
 >>    
 >
 >They can't be combined, because they're invoked on different objects.
 >

Sure they can.  The combined method first does what __with__ would
have done to create abc, and then does whatever abc.__enter__ would
have done.  Since the type of 'abc' is always known to the author of
__with__, this is trivial.

Strictly speaking there's no guarantee that the type of 'abc' is known
to the author of __with__, but I can't imagine an example where that
would not be the case.

 >It would
 >be like trying to combine __iter__() and next() into the same method for
 >iterators. . .

The with-statement needs two pieces of information from the
expression: Which object to bind to the users's variable (VAR) and
which object takes care of block-exit cleanup (abc).  A combined
method would give these two equal standing rather than deriving one
from the other. Nothing ugly about that.

- Anders

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to