<!-- If you're new to Python and you're not sure whether what you're experiencing is a bug, the CPython issue tracker is not the right place to seek help. Consider the following options instead: - reading the Python tutorial: https://docs.python.org/3/tutorial/ - posting in the "Users" category on discuss.python.org: https://discuss.python.org/c/users/7 - emailing the Python-list mailing list: https://mail.python.org/mailman/listinfo/python-list - searching our issue tracker (https://github.com/python/cpython/issues) to see if your problem has already been reported --> # Bug report When using the [`fileinput.hook_compressed`](https://docs.python.org/3/library/fileinput.html#fileinput.hook_compressed) hook in binary mode in the case that the file is *not* compressed, an exception is raised instead of processing the file like normal. ```python # fileinput_cat.py import fileinput import sys with fileinput.input(mode='rb', openhook=fileinput.hook_compressed) as f: for line in f: sys.stdout.buffer.write(line) ``` ```console $ python3.10 fileinput_cat.py fileinput_cat.py Traceback (most recent call last): File "fileinput_bug.py", line 5, in <module> for line in f: File ".../lib/python3.10/fileinput.py", line 256, in __next__ line = self._readline() File ".../lib/python3.10/fileinput.py", line 385, in _readline self._file = self._openhook(self._filename, self._mode) File ".../lib/python3.10/fileinput.py", line 432, in hook_compressed return open(filename, mode, encoding=encoding, errors=errors) ValueError: binary mode doesn't take an encoding argument ``` # Your environment I tried this on Python 3.10.9 (installed from nixpkgs) on Intel macOS 11.7.3. It was working on Python 3.9.16. <!-- gh-linked-prs --> ### Linked PRs * gh-102068 * gh-102098 * gh-102099 <!-- /gh-linked-prs -->