Skip to content

Resource should implement standard pathlib-like interface #562

Open

Description

@lieryan

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.

Activity

  1. added
    cleanupCode quality issues. Linter, type checking, Python 2-ism, Pythonic, etc
    on Nov 30, 2022
  2. added this to the 1.7.0 milestone on Nov 30, 2022
  3. removed this from the 1.7.0 milestone on Jan 17, 2023
  4. moved this to 🆕 New in Kanbanon Jan 17, 2023
  5. moved this from 🆕 New to 📋 Backlog in Kanbanon Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cleanupCode quality issues. Linter, type checking, Python 2-ism, Pythonic, etcenhancement

    Type

    No type

    Projects

    • Status
      📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions