Title: Feedback on new files() and Traverseable API · Issue #90 · python/importlib_resources · GitHub
Open Graph Title: Feedback on new files() and Traverseable API · Issue #90 · python/importlib_resources
X Title: Feedback on new files() and Traverseable API · Issue #90 · python/importlib_resources
Description: In GitLab by @gregory.szorc on Mar 15, 2020, 18:04 I'm attempting to implement the new files() and Traverseable APIs in PyOxidizer and am struggling to figure it out. First, the new classes in abc.py don't have type annotations. I think ...
Open Graph Description: In GitLab by @gregory.szorc on Mar 15, 2020, 18:04 I'm attempting to implement the new files() and Traverseable APIs in PyOxidizer and am struggling to figure it out. First, the new classes in abc....
X Description: In GitLab by @gregory.szorc on Mar 15, 2020, 18:04 I'm attempting to implement the new files() and Traverseable APIs in PyOxidizer and am struggling to figure it out. First, the new classes in ...
Opengraph URL: https://github.com/python/importlib_resources/issues/90
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Feedback on new files() and Traverseable API","articleBody":"In GitLab by @gregory.szorc on Mar 15, 2020, 18:04\n\nI'm attempting to implement the new `files()` and `Traverseable` APIs in PyOxidizer and am struggling to figure it out.\n\nFirst, the new classes in `abc.py` don't have type annotations. I think I can work them out. But being explicit would be much appreciated. Having type annotations would also match the rest of the file.\n\nSecond, the overloading of `Traverseable` to be both a _resource loader_ and an actual resource is a bit confusing. Elsewhere in the `importlib` world, there is a separation between _the interface for loading things_ and _the things returned by that interface_. It is weird to me that a single `Traverseable` both represents the returned value from `files()` (a logical collection of resources or a mechanism to obtain resources) as well as a _handle_ on an individual resource. I would like for these interfaces to be teased apart, if possible. More on this later.\n\nThird - and this is related to the last point - I just don't understand how you are supposed to handle directories in all cases. Because `Traversable` is both a loader and a handle on an individual resource, what are we supposed to do for operations like calling `Traverseable.open()` on an object that represents a directory? Are we supposed to return `None`? Raise an `OsError` or `IoError` or whatever the OS emits when you try to open a directory? Do we assume the caller calls `is_dir()` / `is_file()` and isn't dumb enough to call `open()` on a directory? But what if they do?\n\nFourth, I don't understand why there exists an `open`, `read_text`, and `read_bytes` on `Traverseable`. `read_text` and `read_bytes` can be implemented in terms of `open()`. So why are they a) abstract b) part of the interface in the first place? If we're going to provide `open()`, I think it makes sense to expose helper functions for `read_text` and `read_bytes` that are implemented in terms of `open()`.\n\nFifth, to be honest, I'm not a huge fan of `open()` because it puts a lot of burden on custom implementations. What subset of `Path.open()` needs to be implemented? `Path.open()` is supposed to accept `mode`, `buffering`, `encoding`, `errors`, and `newline` arguments. Since these are all `*args, **kwrags`-awayed in the interface and the docs only call out `mode`, what is supposed to be supported? Is it really reasonable for custom implementations (which may not be able to simply call out to `builtins.open()` because they aren't using a traditional filesystem) to have to implement all this functionality? I would highly encourage reducing the scope of `open()` to binary file reading. Remove buffering, encoding, errors, and newline support. If people really want to buffer or read resources as text, they can use `io.BufferedReader` and/or `io.TextIOWrapper`. And of course, helper APIs that wrap low-level binary-only file-like objects can exist to make `read_text()` a trivial one-liner. Or consider making the text reading APIs optional and having the default resource reading code go through a polyfill that uses `io.*` wrappers accordingly.\n\nI want to say the new `files()` + `Traverseable` API is a net improvement and thank everybody responsible. But at this point in time, I feel like the pile of warts I described in #58 has more or less been replaced by a different pile of warts :/ I failed to see the new API being designed and feel like I missed an opportunity to influence its design towards something more reasonable for advanced use cases like PyOxidizer. For that I feel bad and apologize. If it isn't too late to make backwards-incompatible changes to the interface, I would strongly vote for reducing the scope of `open()` and removing `read_text` and `read_bytes`. If we do that and clarify the interface and semantics a bit more, I think this new API will be clearly better than what came before.","author":{"url":"https://github.com/jaraco","@type":"Person","name":"jaraco"},"datePublished":"2020-10-21T22:13:48Z","url":"https://github.com/python/importlib_resources/issues/90"}
| 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:6a296f82-93c5-43a2-6d1b-da720076c428 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BBD4:1833B7:2C18329:3C0ACC3:6B0057AE |
| html-safe-nonce | 4213dadbce06225132084500b7eaacce84b3199ef200caccf16ace1c66db0dc0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQkQ0OjE4MzNCNzoyQzE4MzI5OjNDMEFDQzM6NkIwMDU3QUUiLCJ2aXNpdG9yX2lkIjoiODExNTk3OTUyMzg0MjkyMjQxNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 43a225a2049a36a5b25289a947c3f4ed2a8d6cde652e26f534e15151c8c14328 |
| hovercard-subject-tag | issue:726899020 |
| 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/importlib_resources/90/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9bef4a8a837c06421116c4c4f5daccdc14f673d4ab4576fbf71be84ad3199e9c/python/importlib_resources/issues/90 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9bef4a8a837c06421116c4c4f5daccdc14f673d4ab4576fbf71be84ad3199e9c/python/importlib_resources/issues/90 |
| og:image:alt | In GitLab by @gregory.szorc on Mar 15, 2020, 18:04 I'm attempting to implement the new files() and Traverseable APIs in PyOxidizer and am struggling to figure it out. First, the new classes in abc.... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jaraco |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| turbo-cache-control | no-preview |
| go-import | github.com/python/importlib_resources git https://github.com/python/importlib_resources.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 306147182 |
| octolytics-dimension-repository_nwo | python/importlib_resources |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 306147182 |
| octolytics-dimension-repository_network_root_nwo | python/importlib_resources |
| 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 | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width