A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-October/057117.html below:

[Python-Dev] Proposed changes to PEP 343

[Python-Dev] Proposed changes to PEP 343Anders J. Munch andersjm at inbound.dk
Sun Oct 9 16:00:04 CEST 2005
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

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4