-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Document importlib.resources.abc.Traversable #91298
Comments
importlib.resources.files is documented 0 as returning importlib.resources.abc.Traversable, which is an undocumented class (dead link) now. It should be documented.
|
Good question. Currently, I'm aware of three concrete implementations of Traversable.joinpath:
For zipfile.Path, I observe that joinpath does accept path separators but looking at the docs for zipfile, it's not even obvious to me what path separators are used in zipfiles, but I do observe there is coercion to posixpath.sep.
Here's what I propose:
|
The short answer is no. The protocol does not stipulate specific exceptions. Perhaps it should be documented that any exceptions that occur when accessing the backing resource will propagate. Although, I do believe that statement is true for all Python code unless stated otherwise. I agree it would be nice if the protocol could stipulate which exceptions might be raised by a given implementation, but I'm not confident that's possible, at least not without wrapping/adapting the pathlib.Path and zipfile.Path objects. Does that answer the question? Are you working on another provider that implements this protocol? I'd be happy to consult on that effort. |
Correction. In msg416618, link should have been: |
Right, that could be improved. IMO it could link to the constructor docs that have all the details. Forward slashes work on all supported systems. On Windows they're equivalent to backslashes (everywhere except in old CLI commands, AFAIK). So it makes sense to normalize to them. >>> PureWindowsPath('a/b\\c')
PureWindowsPath('a/b/c') pathlib.Path.joinpath also allows
Yes. Thank you! try:
return pkg_files.joinpath(f'templates/{user_supplied_name}').read_text()
except (NoSuchFileError, IsADirectoryError):
raise ... which suggests another question: should I expect resilience against path traversal attacks?
No, I'm just trying to make sense of it all. |
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: