On 10/9/05, Anders J. Munch <[EMAIL PROTECTED]> wrote:
> 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.

I'm sure it can be done, but I find this ugly API design. While I'm
not keen on complicating the API, the decimal context example has
convinced me that it's necessary. The separation into __with__ which
asks EXPR for a context manager and __enter__ / __exit__ which handle
try/finally feels right. An API returning a tuple is asking for bugs.

--
--Guido van Rossum (home page: http://www.python.org/~guido/)
_______________________________________________
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