Author ncoghlan
Recipients jwp, ncoghlan
Date 2010-11-05.14:27:52
SpamBayes Score 5.76639e-06
Marked as misclassified No
Message-id <>
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__()
  if hasattr(cm, "__entered__"):
    VAL = cm.__entered__(_v)
    VAL = _v
  # do stuff

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.
Date User Action Args
2010-11-05 14:27:55ncoghlansetrecipients: + ncoghlan, jwp
2010-11-05 14:27:55ncoghlansetmessageid: <>
2010-11-05 14:27:53ncoghlanlinkissue5251 messages
2010-11-05 14:27:52ncoghlancreate