Barry A. Warsaw <ba...@python.org> added the comment: > A LBYL won't always raise errors early as you point out. It will give earlier > warnings for a lot of cases, but makes contextlib.chdir usable in less places > than os.chdir. > Some return paths will always be errors, and some will be technically > recoverable but too difficult to detect and or fragile. That's why I think > any solution should incorporate the `ignore_errors` flag. Its pretty ugly to > wrap a context manager in a try: except: just because you were trying to > clean up after whatever you were doing but the cwd changed in unexpected > ways, maybe out of your control.
How common do you expect such errors to be though? Do you expect them to be more or less common than with os.chdir()? Do you expect the mitigations to be any different than with a failing os.chdir()? I’ve certainly written a chdir context manager several times and for the use cases I care about, I’ve never had such a failure, at least not one that wasn’t caused by some other underlying bug, which I was glad wasn’t silenced. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45545> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com