Title: `zipfile.Path.read_text` & `.open` methods with a positional `encoding` arg causes a TypeError · Issue #101144 · python/cpython · GitHub
Open Graph Title: `zipfile.Path.read_text` & `.open` methods with a positional `encoding` arg causes a TypeError · Issue #101144 · python/cpython
X Title: `zipfile.Path.read_text` & `.open` methods with a positional `encoding` arg causes a TypeError · Issue #101144 · python/cpython
Description: This is a regression from 3.9 behavior seen in Python 3.10. zipfile.Path.read_text passes *args and **kwargs to it's own open() method, but in 3.10+ is also blindly sets kwargs["encodings"] to a value. So code that was previously passing...
Open Graph Description: This is a regression from 3.9 behavior seen in Python 3.10. zipfile.Path.read_text passes *args and **kwargs to it's own open() method, but in 3.10+ is also blindly sets kwargs["encodings"] to a va...
X Description: This is a regression from 3.9 behavior seen in Python 3.10. zipfile.Path.read_text passes *args and **kwargs to it's own open() method, but in 3.10+ is also blindly sets kwargs["encodings&...
Opengraph URL: https://github.com/python/cpython/issues/101144
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`zipfile.Path.read_text` \u0026 `.open` methods with a positional `encoding` arg causes a TypeError","articleBody":"This is a regression from 3.9 behavior seen in Python 3.10.\r\n\r\nzipfile.Path.read_text passes *args and **kwargs to it's own `open()` method, but in 3.10+ is also blindly sets `kwargs[\"encodings\"]` to a value. So code that was previously passing an encoding as a positional argument now sees:\r\n\r\n```\r\n File \"/\u003cstdlib\u003e/zipfile.py\", line 2362, in read_text\r\n with self.open('r', *args, **kwargs) as strm:\r\n File \"/\u003cstdlib\u003e/zipfile.py\", line 2350, in open\r\n return io.TextIOWrapper(stream, *args, **kwargs)\r\nTypeError: Failed to construct dataset imagenet2012: argument for TextIOWrapper() given by name ('encoding') and position (2)\r\n```\r\n\r\n3.10's Lib/zipfile.py (and main's Lib/zipfile/_path.py) contain:\r\n\r\n```\r\n def read_text(self, *args, **kwargs):\r\n kwargs[\"encoding\"] = io.text_encoding(kwargs.get(\"encoding\")) # \u003c-- new in 3.10, source of bug\r\n with self.open('r', *args, **kwargs) as strm:\r\n return strm.read()\r\n```\r\n\r\nAs this is a regression, we should avoid setting that value in kwargs when `\"encodings\" not in kwargs` to match 3.9 and earlier behavior.\r\n\r\nTODO list:\r\n\r\n- [x] @jaraco will port the change to [zipp](/jaraco/zipp).\r\n\r\n\u003c!-- gh-linked-prs --\u003e\r\n### Linked PRs\r\n* gh-101145\r\n* gh-101179\r\n* gh-101182\r\n\u003c!-- /gh-linked-prs --\u003e\r\n","author":{"url":"https://github.com/gpshead","@type":"Person","name":"gpshead"},"datePublished":"2023-01-19T01:47:13.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/101144/cpython/issues/101144"}
| 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:57a6e70d-2683-a4b3-7d7c-f10f9d68d185 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E7DA:390ECE:4526957:61B432A:6A56C46E |
| html-safe-nonce | 1a44463004e89a6c729672d2212bf2b52972887366f531151ca20f6231bf5fb6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFN0RBOjM5MEVDRTo0NTI2OTU3OjYxQjQzMkE6NkE1NkM0NkUiLCJ2aXNpdG9yX2lkIjoiODM3MzE4OTA0MjI5ODM5OTgyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7d15612bea7ce472dbcde612dce747aacb9fc93586a0d8c12382e7aa3bd8d1db |
| hovercard-subject-tag | issue:1548395059 |
| 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/101144/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a927e5f84173c2bbcc7bf5241d9a874399be45d5b88ea1fe4982246d658d9d7c/python/cpython/issues/101144 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a927e5f84173c2bbcc7bf5241d9a874399be45d5b88ea1fe4982246d658d9d7c/python/cpython/issues/101144 |
| og:image:alt | This is a regression from 3.9 behavior seen in Python 3.10. zipfile.Path.read_text passes *args and **kwargs to it's own open() method, but in 3.10+ is also blindly sets kwargs["encodings"] to a va... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gpshead |
| hostname | github.com |
| expected-hostname | github.com |
| None | df99b7164e1d961b639cf5d3cbd6b5ba673edc67bd7e47cdc4746b96099e11ae |
| 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 | 3146ab55fc8763ab0e1d2a875e600b3a545bc751 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width