13.07.19 23:25, Kyle Stanley пише:
Serhiy Storchaka wrote:
Are your aware of contextlib.nested()? And why it was deprecated and removed?
Was contextlib.nested() removed primarily due to to the inconsistencies mentioned in https://bugs.python.org/issue5251 or was it something else?
Yes, it was removed because of the inherent flaw of such design. In `with nested(open('a'), open('b'))` if the second open failed, the first file will be leaked. No nested() object even be created, so this can't be fixed in it. There is exactly the same problem with using a tuple as a context manager.