Skip to content
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

Resource should implement standard pathlib-like interface #562

Open
lieryan opened this issue Nov 30, 2022 · 0 comments
Open

Resource should implement standard pathlib-like interface #562

lieryan opened this issue Nov 30, 2022 · 0 comments
Labels
cleanup Code quality issues. Linter, type checking, Python 2-ism, Pythonic, etc enhancement

Comments

@lieryan
Copy link
Member

lieryan commented Nov 30, 2022

What needed to be changed to make Resource, File, and Folder implement a pathlib-like interface:

  1. Resource should implement os.PathLike Implement os.PathLike on Resource #738
  2. File.read() should be deprecated, renamed to File.read_text()
  3. File.write() should be deprecated,
  4. File.write_text() and File.write_bytes() should be implemented
  5. File.is_folder() and Folder.is_folder() should be deprecated, renamed to .is_dir() (done in Implement os.PathLike on Resource #738)
  6. Implement Resource.is_file()
  7. Implement the / operator as an alias to get_child()
  8. Implement Folder.iterdir()
  9. Folder.get_children() should be rewritten to call return list(self.iterdir())
  10. Resource should inherit PurePath (rather questionable, Resource is not necessarily a Path on the filesystem, it may represent a file in a zipfile module)

The purpose here is not to make Resource usable in contexts where Path is expected, but rather simply just to standardize the vocabularies of path operations.

There is no plan to make Resource implement the entire pathlib interface; most of it doesn't make sense for rope's purpose and would only make using Resource class unnecessarily confusing (e.g. is_block_device() would never make sense for rope). If you need a real pathlib object, then access the Resource.pathlib property or convert the pathlib.Path(resource) which would use __fspath__ interface.

@lieryan lieryan added enhancement cleanup Code quality issues. Linter, type checking, Python 2-ism, Pythonic, etc labels Nov 30, 2022
@lieryan lieryan added this to the 1.7.0 milestone Nov 30, 2022
@lieryan lieryan mentioned this issue Dec 14, 2022
@lieryan lieryan removed this from the 1.7.0 milestone Jan 17, 2023
@lieryan lieryan added this to Kanban Jan 17, 2023
@lieryan lieryan moved this to 🆕 New in Kanban Jan 17, 2023
@lieryan lieryan moved this from 🆕 New to 📋 Backlog in Kanban Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code quality issues. Linter, type checking, Python 2-ism, Pythonic, etc enhancement
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant