Author ncoghlan
Recipients docs@python, ezio.melotti, ncoghlan, terry.reedy, yak
Date 2012-01-22.06:58:15
SpamBayes Score 0.0010966
Marked as misclassified No
Message-id <1327215497.25.0.0529876633689.issue13814@psf.upfronthosting.co.za>
In-reply-to
Content
Generators deliberately don't support the context management protocol. This is so that they raise an explicit TypeError or AttributeError (pointing out that __exit__ is missing) if you leave out the @contextmanager decorator when you're using a generator to write an actual context manager.

Generators supporting the context management protocol natively would turn that into a far more subtle (and confusing) error: your code would silently fail to invoke the generator body.

Ensuring this common error remains easy to detect is far more important than making it easier to invoke close() on a generator object (particularly when contextlib.closing() already makes that very easy).
History
Date User Action Args
2012-01-22 06:58:17ncoghlansetrecipients: + ncoghlan, terry.reedy, ezio.melotti, docs@python, yak
2012-01-22 06:58:17ncoghlansetmessageid: <1327215497.25.0.0529876633689.issue13814@psf.upfronthosting.co.za>
2012-01-22 06:58:16ncoghlanlinkissue13814 messages
2012-01-22 06:58:15ncoghlancreate