Title: Exception using fileinput.hook_compressed in binary mode · Issue #101961 · python/cpython · GitHub
Open Graph Title: Exception using fileinput.hook_compressed in binary mode · Issue #101961 · python/cpython
X Title: Exception using fileinput.hook_compressed in binary mode · Issue #101961 · python/cpython
Description: Bug report When using the 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. # fileinput_cat.py import fileinput import sys with f...
Open Graph Description: Bug report When using the 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. # fileinput_c...
X Description: Bug report When using the 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. # fileinput_c...
Opengraph URL: https://github.com/python/cpython/issues/101961
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Exception using fileinput.hook_compressed in binary mode","articleBody":"\u003c!--\r\n 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\r\n the right place to seek help. Consider the following options instead:\r\n\r\n - reading the Python tutorial: https://docs.python.org/3/tutorial/\r\n - posting in the \"Users\" category on discuss.python.org: https://discuss.python.org/c/users/7\r\n - emailing the Python-list mailing list: https://mail.python.org/mailman/listinfo/python-list\r\n - searching our issue tracker (https://github.com/python/cpython/issues) to see if\r\n your problem has already been reported\r\n--\u003e\r\n\r\n# Bug report\r\n\r\nWhen 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.\r\n\r\n```python\r\n# fileinput_cat.py\r\n\r\nimport fileinput\r\nimport sys\r\n\r\nwith fileinput.input(mode='rb', openhook=fileinput.hook_compressed) as f:\r\n for line in f:\r\n sys.stdout.buffer.write(line)\r\n```\r\n\r\n```console\r\n$ python3.10 fileinput_cat.py fileinput_cat.py\r\nTraceback (most recent call last):\r\n File \"fileinput_bug.py\", line 5, in \u003cmodule\u003e\r\n for line in f:\r\n File \".../lib/python3.10/fileinput.py\", line 256, in __next__\r\n line = self._readline()\r\n File \".../lib/python3.10/fileinput.py\", line 385, in _readline\r\n self._file = self._openhook(self._filename, self._mode)\r\n File \".../lib/python3.10/fileinput.py\", line 432, in hook_compressed\r\n return open(filename, mode, encoding=encoding, errors=errors)\r\nValueError: binary mode doesn't take an encoding argument\r\n```\r\n\r\n# Your environment\r\n\r\nI tried this on Python 3.10.9 (installed from nixpkgs) on Intel macOS 11.7.3. It was working on Python 3.9.16.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-102068\n* gh-102098\n* gh-102099\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/gmacon","@type":"Person","name":"gmacon"},"datePublished":"2023-02-16T19:58:20.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/101961/cpython/issues/101961"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b24d3e97-246a-798a-d8b8-6738d9633de4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DC22:4F147:1921465:21B4088:6969AE28 |
| html-safe-nonce | 4326c01b65e68093d838adba13951dc388b9b405368230ba697030b0faffb63a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzIyOjRGMTQ3OjE5MjE0NjU6MjFCNDA4ODo2OTY5QUUyOCIsInZpc2l0b3JfaWQiOiI0MTc4MTgzNjczOTgzNTg1NjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | df666f8045fafa45f036157cf2a4ed3dd797b9d2a7720543b9fdbc30b4e57514 |
| hovercard-subject-tag | issue:1588283296 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/101961/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4e1c149588a7309cabf4eb091e96e94a4af1e8488dd4be3df7e21dd53360b55a/python/cpython/issues/101961 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4e1c149588a7309cabf4eb091e96e94a4af1e8488dd4be3df7e21dd53360b55a/python/cpython/issues/101961 |
| og:image:alt | Bug report When using the 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. # fileinput_c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gmacon |
| hostname | github.com |
| expected-hostname | github.com |
| None | 24c4c97a2d520cb286b35e1a4c22d7a4df3c26a2fa28dd7cdf0e65db327b4de7 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 124667f43168afb6c9c03b7c02eb5b1d2e1be3d9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width