Irit Katriel <iritkatr...@yahoo.com> added the comment:
For the original problem, how about this? def process_file(file_or_path): if isinstance(file_or_path, str): # If string, open file cm = open else: # Caller is responsible for closing file cm = nullcontext with cm(file_or_path) as file: # Perform processing on the file ---------- nosy: +iritkatriel _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue34067> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com