[Python-Dev] PEP 343 - Abstract Block Redux
Phillip J. Eby
pje at telecommunity.com
Sat May 14 03:10:07 CEST 2005
At 05:13 PM 5/13/2005 -0700, Guido van Rossum wrote:
>I've written up the specs for my "PEP 340 redux" proposal as a
>separate PEP, PEP 343.
>
>http://python.org/peps/pep-0343.html
>
>Those who have been following the thread "Merging PEP 310 and PEP
>340-redux?" will recognize my proposal in that thread, which received
>mostly positive responses there.
>
>Please review and ask for clarifications of anything that's unclear.
May I suggest this alternative translation in the "Specification" section:
abc = EXPR
__args = () # pseudo-variable, not visible to the user
try:
VAR = abc.__enter__()
try:
BLOCK
except:
__args = sys.exc_info()
finally:
abc.__exit__(*__args)
While slighly more complex than the current translation, the current
translation seems a bit misleading to me. OTOH, that may simply be because
I see the *sys.exc_info() part and immediately wonder what happens when
there was no exception, and sys.exc_info() contains some arbitrary previous
data...
Also, one question: will the "do protocol" be added to built-in "resource"
types? That is, locks, files, sockets, and so on? Or will there instead
be "macros" like the "opening" and "locking" templates? I notice that
grammatically, "do gerund" works a lot better than "do noun", so all of
your examples are words like locking, blocking, opening, redirecting, and
so on. This makes it seem awkward for e.g. "do self.__lock", which doesn't
make any sense. But the extra call needed to make it "do
locking(self.__lock)" seems sort of gratuitous.
It makes me wonder if "with" or "using" or some similar word that works
better with nouns might be more appropriate, as then it would let us just
add the resource protocol to common objects, and still read well. For
example, a Decimal Context object might implement __enter__ by setting
itself as the thread-local context, and __exit__ by restoring the previous
context. "do aDecimalContext" doesn't make much sense, but "with
aDecimalContext" or "using aDecimalContext" reads quite nicely.
More information about the Python-Dev
mailing list