Author ncoghlan
Recipients jwp, ncoghlan
Date 2010-11-05.14:27:52
SpamBayes Score 5.76639e-06
Marked as misclassified No
Message-id <1288967275.14.0.524569341323.issue5251@psf.upfronthosting.co.za>
In-reply-to
Content
Reopening as a reminder to myself that I have a new PEP I want to write in this area. The idea is essentially a lighter weight alternative to PEP 377 that adds an optional __entered__ method to the context management protocol along the following lines:

_v = cm.__enter__()
try:
  if hasattr(cm, "__entered__"):
    VAL = cm.__entered__(_v)
  else:
    VAL = _v
  # do stuff
finally:
  cm.__exit__(*exception_status)

Providing a second, optional method that is executed *inside* the body will let CMs do things they can't do now (like skip the body of the with statement) without significantly affecting the behaviour of normal CMs. Notably, GeneratorContextManager will be able to use this to more gracefully handle the case where the generator doesn't yield a value.

I plan to flesh this out into a python-ideas post (and likely a subsequent PEP) at some point in the next few months.
History
Date User Action Args
2010-11-05 14:27:55ncoghlansetrecipients: + ncoghlan, jwp
2010-11-05 14:27:55ncoghlansetmessageid: <1288967275.14.0.524569341323.issue5251@psf.upfronthosting.co.za>
2010-11-05 14:27:53ncoghlanlinkissue5251 messages
2010-11-05 14:27:52ncoghlancreate