Serhiy Storchaka added the comment: I prefer the current code (i.e. formatter_fix_resource_warning_v5.patch).
In more complex case ExitStack can be used, but here it looks redundant. with contextlib.ExitStack() as stack: if some_test: fl = open(sys.argv[1]) stack.enter_context(fl) else: fl = sys.stdin do_stuff(fl) or if some_test: cm = fl = open(sys.argv[1]) else: fl = sys.stdin cm = contextlib.ExitStack() with cm: do_stuff(fl) ---------- nosy: +serhiy.storchaka _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue18644> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com