Title: str(zipfile.Path()) not working when root attribute is io.BytesIO · Issue #100609 · python/cpython · GitHub
Open Graph Title: str(zipfile.Path()) not working when root attribute is io.BytesIO · Issue #100609 · python/cpython
X Title: str(zipfile.Path()) not working when root attribute is io.BytesIO · Issue #100609 · python/cpython
Description: Using zipfile.Path with a ZIP-file "in memory" as io.BytesIO instance. In that case attributes like .filename() or .__str__() do not work because they try to instanciate a pathlib.Path() with a io.BytesIO object. I can confirm this with ...
Open Graph Description: Using zipfile.Path with a ZIP-file "in memory" as io.BytesIO instance. In that case attributes like .filename() or .__str__() do not work because they try to instanciate a pathlib.Path() with a io....
X Description: Using zipfile.Path with a ZIP-file "in memory" as io.BytesIO instance. In that case attributes like .filename() or .__str__() do not work because they try to instanciate a pathlib.Path() ...
Opengraph URL: https://github.com/python/cpython/issues/100609
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"str(zipfile.Path()) not working when root attribute is io.BytesIO","articleBody":"Using `zipfile.Path` with a ZIP-file \"in memory\" as `io.BytesIO` instance. In that case attributes like `.filename()` or `.__str__()` do not work because they try to instanciate a `pathlib.Path()` with a `io.BytesIO` object.\r\n\r\nI can confirm this with Python 3.11 (run in Docker), Python 3.10.2 (Windows) and Python 3.9.2 (Debian stable). See output below for detailed version infos.\r\n\r\n# Code to reproduce\r\n\r\n```python \r\n#!/usr/bin/env python3\r\nimport sys\r\nimport io\r\nimport pathlib\r\nimport zipfile\r\n\r\nprint('{} {}\\n'.format(sys.platform, sys.version))\r\n\r\nzip_bytes = io.BytesIO()\r\n\r\n# create a zipfile in memory\r\nwith zipfile.ZipFile(zip_bytes, 'w') as zf:\r\n zf.writestr('entry.file', 'content')\r\n\r\n# ZIP-Path object from in-memory-ZIP\r\nmy_zip_path = zipfile.Path(zip_bytes, 'entry.file')\r\nprint('Exists {}'.format(my_zip_path.exists()))\r\n\r\n# here comes the Exception\r\nprint(my_zip_path)\r\n```\r\n\r\n# Output: Python 3.11 on Linux/Docker\r\n\r\n```\r\nDigest: sha256:250990a809a15bb6a3e307fec72dead200c882c940523fb1694baa78eb0e47c6\r\nStatus: Downloaded newer image for python:3.11\r\nPython 3.11.1 (main, Dec 21 2022, 18:32:57) [GCC 10.2.1 20210110] on linux\r\n......\r\nTraceback (most recent call last):\r\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\r\n File \"/usr/local/lib/python3.11/zipfile.py\", line 2421, in filename\r\n return pathlib.Path(self.root.filename).joinpath(self.at)\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n File \"/usr/local/lib/python3.11/pathlib.py\", line 871, in __new__\r\n self = cls._from_parts(args)\r\n ^^^^^^^^^^^^^^^^^^^^^\r\n File \"/usr/local/lib/python3.11/pathlib.py\", line 509, in _from_parts\r\n drv, root, parts = self._parse_args(args)\r\n ^^^^^^^^^^^^^^^^^^^^^^\r\n File \"/usr/local/lib/python3.11/pathlib.py\", line 493, in _parse_args\r\n a = os.fspath(a)\r\n ^^^^^^^^^^^^\r\nTypeError: expected str, bytes or os.PathLike object, not NoneType\r\n\r\n```\r\n\r\n# Output: Python 3.10 on Windows\r\n\r\n```\r\nwin32 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)]\r\n\r\nExists True\r\nTraceback (most recent call last):\r\n File \"C:\\Users\\buhtzch\\ownCloud\\my.work\\buhtzology\\zippathbug.py\", line 28, in \u003cmodule\u003e\r\n print(my_zip_path)\r\n File \"C:\\Program Files\\Python310\\lib\\zipfile.py\", line 2380, in __str__\r\n return posixpath.join(self.root.filename, self.at)\r\n File \"C:\\Program Files\\Python310\\lib\\posixpath.py\", line 76, in join\r\n a = os.fspath(a)\r\nTypeError: expected str, bytes or os.PathLike object, not NoneType\r\n```\r\n\r\n# Output: Python 3.9.2 on Debian stable (11)\r\n\r\n```\r\nlinux 3.9.2 (default, Feb 28 2021, 17:03:44)\r\n[GCC 10.2.1 20210110]\r\n\r\nExists True\r\nTraceback (most recent call last):\r\n File \"/home/user/ownCloud/my.work/buhtzology/zippathbug.py\", line 28, in \u003cmodule\u003e\r\n print(my_zip_path)\r\n File \"/usr/lib/python3.9/zipfile.py\", line 2347, in __str__\r\n return posixpath.join(self.root.filename, self.at)\r\n File \"/usr/lib/python3.9/posixpath.py\", line 76, in join\r\n a = os.fspath(a)\r\nTypeError: expected str, bytes or os.PathLike object, not NoneType\r\n```","author":{"url":"https://github.com/buhtz","@type":"Person","name":"buhtz"},"datePublished":"2022-12-29T21:51:55.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":12},"url":"https://github.com/100609/cpython/issues/100609"}
| 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:9e65b656-4d79-78e8-fde4-8a1b711174d7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 853A:1B40D2:375645:4BD5B2:6969DA64 |
| html-safe-nonce | e2f3b86e8bcd237db97bdb9dbb2d29d67ab20f987521ce63bac4295030791bd8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NTNBOjFCNDBEMjozNzU2NDU6NEJENUIyOjY5NjlEQTY0IiwidmlzaXRvcl9pZCI6IjY3NTkyMjk5NzM4MzE3MzU5MDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9919461b189b9e4b3b031874b7df92884d09ba773d8430ca0b544f2f8e591dc8 |
| hovercard-subject-tag | issue:1514074925 |
| 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/100609/issue_layout |
| twitter:image | https://opengraph.githubassets.com/17a050cbfafb1e2f3cdd7f9bb8a4d0c3602277415ba0836bfa1ab7c3306a1a16/python/cpython/issues/100609 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/17a050cbfafb1e2f3cdd7f9bb8a4d0c3602277415ba0836bfa1ab7c3306a1a16/python/cpython/issues/100609 |
| og:image:alt | Using zipfile.Path with a ZIP-file "in memory" as io.BytesIO instance. In that case attributes like .filename() or .__str__() do not work because they try to instanciate a pathlib.Path() with a io.... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | buhtz |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7b32f1c7c4549428ee399213e8345494fc55b5637195d3fc5f493657579235e8 |
| 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 | bdde15ad1b403e23b08bbd89b53fbe6bdf688cad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width