-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recommend importlib.abc.Traversable users to implement __fspath__ #88366
Comments
The files()/Traversable api is meant to replace ResourceReader api, but it falls short in one dimension, tying the abstraction to a file system path. I propose to document that Traversable users *should* implement __fspath__ if the Traversable represents a file-system path. This will essentially make os.fspath(importlib.resources.files(module) / resource) the equivalent of importlib.resources.path(module, resource), for which currently there is no replacement using files(). |
The problem with the Does that satisfy the need you've identified? |
That's why I said it should be optional. If the object can implement it, it should. I think |
Oh, that's an interesting idea. And that's effectively what happens here, where Only thing is, that code would serve no purpose until there existed at least one other resource provider besides FileReader that has file-system-local resources. I'm not aware of any such provider. |
CompatibilityFiles would use this. We could add a dispatch for that too, but that's 2 different cases now and |
This comment was marked as off-topic.
This comment was marked as off-topic.
I'm not sure I understand the two cases. Perhaps you could illustrate how this would work within CompatibilityFiles? |
Currently, if I need to access a resource as a file on the filesystem, I need to use But I feel like a better solution would be to have the
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: