Message151763
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). |
|
Date |
User |
Action |
Args |
2012-01-22 06:58:17 | ncoghlan | set | recipients:
+ ncoghlan, terry.reedy, ezio.melotti, docs@python, yak |
2012-01-22 06:58:17 | ncoghlan | set | messageid: <1327215497.25.0.0529876633689.issue13814@psf.upfronthosting.co.za> |
2012-01-22 06:58:16 | ncoghlan | link | issue13814 messages |
2012-01-22 06:58:15 | ncoghlan | create | |
|