Title: importlib.resources regression for custom ResourceReader · Issue #127337 · python/cpython · GitHub
Open Graph Title: importlib.resources regression for custom ResourceReader · Issue #127337 · python/cpython
X Title: importlib.resources regression for custom ResourceReader · Issue #127337 · python/cpython
Description: Since Python 3.13 (including 3.14), my custom ResourceReader is now raising errors when used with importlib.resources.contents. This code is otherwise functioning fine from 3.8 onwards. Traceback (most recent call last): File "D:\cpython...
Open Graph Description: Since Python 3.13 (including 3.14), my custom ResourceReader is now raising errors when used with importlib.resources.contents. This code is otherwise functioning fine from 3.8 onwards. Traceback (...
X Description: Since Python 3.13 (including 3.14), my custom ResourceReader is now raising errors when used with importlib.resources.contents. This code is otherwise functioning fine from 3.8 onwards. Traceback (...
Opengraph URL: https://github.com/python/cpython/issues/127337
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"importlib.resources regression for custom ResourceReader","articleBody":"Since Python 3.13 (including 3.14), my custom ResourceReader is now raising errors when used with `importlib.resources.contents`. This code is otherwise functioning fine from 3.8 onwards.\r\n\r\n```\r\nTraceback (most recent call last):\r\n File \"D:\\cpython\\t.py\", line 41, in \u003cmodule>\r\n print(contents(FakeModule))\r\n ~~~~~~~~^^^^^^^^^^^^\r\n File \"D:\\cpython\\Lib\\importlib\\resources\\_functional.py\", line 60, in contents\r\n return (resource.name for resource in _get_resource(anchor, path_names).iterdir())\r\n ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^\r\n File \"D:\\cpython\\Lib\\importlib\\resources\\_functional.py\", line 81, in _get_resource\r\n return files(anchor).joinpath(*path_names)\r\n ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^\r\nTypeError: CompatibilityFiles.SpecPath.joinpath() missing 1 required positional argument: 'other'\r\n```\r\n\r\nSelf-contained repro below (the real one gets compiled into DLLs, so you don't want to try to debug it ;) ):\r\n\r\n```python\r\nfrom importlib.abc import Loader\r\nfrom importlib.machinery import ModuleSpec\r\nfrom importlib.resources.abc import ResourceReader\r\n\r\n_DATA = {\"FakeModule.NAME\": b\"hello\"}\r\n_DATA_NAMES = set(_DATA)\r\n\r\nclass MyReader(ResourceReader):\r\n def __init__(self, prefix):\r\n self.prefix = prefix\r\n\r\n def open_resource(self, resource):\r\n import io\r\n return io.BytesIO(_DATA[self.prefix + resource])\r\n\r\n def resource_path(self, resource):\r\n raise FileNotFoundError()\r\n\r\n def is_resource(self, resource):\r\n return self.prefix + resource in _DATA_NAMES\r\n\r\n def contents(self):\r\n p = self.prefix\r\n lp = len(p)\r\n return (n[lp:] for n in _DATA_NAMES if n.startswith(p))\r\n\r\nclass MyLoader(Loader):\r\n create_module = ...\r\n exec_module = ...\r\n\r\n def get_resource_reader(self, fullname):\r\n return MyReader(fullname + \".\")\r\n\r\nclass FakeModule:\r\n __loader__ = MyLoader()\r\n __name__ = \"FakeModule\"\r\n __spec__ = ModuleSpec(__name__, __loader__)\r\n\r\nfrom importlib.resources import contents\r\nprint(contents(FakeModule))\r\n```\r\n\r\n(ping @jaraco)\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-154919\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/zooba","@type":"Person","name":"zooba"},"datePublished":"2024-11-27T15:42:03Z","url":"https://github.com/python/cpython/issues/127337"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:3acb463f-e681-75df-761c-5c411ea464bd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8D9C:177D5B:35565D9:46C368D:6B004244 |
| html-safe-nonce | 0c59edaf736a5fbb60239a05c75abf8f6d400adc26f2a8e3c97c56f3c056109b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RDlDOjE3N0Q1QjozNTU2NUQ5OjQ2QzM2OEQ6NkIwMDQyNDQiLCJ2aXNpdG9yX2lkIjoiNzM1NDgzMjg0NTY0NDI1MTcxNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7c3c7f5bdc444145bc50e655f2da640e7816b5fa8c16ccf7dbaa550266807314 |
| hovercard-subject-tag | issue:2698999968 |
| 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/127337/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9c27bda45ae72fdc322f9be34bfabdffb79b97ae7ff6963e25b1fcd7852b9614/python/cpython/issues/127337 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9c27bda45ae72fdc322f9be34bfabdffb79b97ae7ff6963e25b1fcd7852b9614/python/cpython/issues/127337 |
| og:image:alt | Since Python 3.13 (including 3.14), my custom ResourceReader is now raising errors when used with importlib.resources.contents. This code is otherwise functioning fine from 3.8 onwards. Traceback (... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zooba |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width