Message151763
| Author |
ncoghlan |
| Recipients |
docs@python, ezio.melotti, ncoghlan, terry.reedy, yak |
| Date |
2012年01月22日.06:58:15 |
| SpamBayes Score |
0.0010965992 |
| 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: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 |
|