Skip to content

pathlib ABCs: add protocols for supporting types #127456

Description

@barneygale

Feature or enhancement

For typing and documentation purposes, it would be useful to define three protocols in pathlib:

  • Parser: like os.path, but including only pure functionality that's essential for PurePathBase
  • DirEntry: like os.DirEntry, but without some non-portable methods (like inode())
  • StatResult: like os.stat_result, but without the tuple-like interface, and dropping non-essential attributes

These could be defined in a private module like pathlib._types. For performance reasons that module shouldn't be imported by any other pathlib module.

If/when we make PathBase public, we'll also make these protocols public.

See also: https://discuss.python.org/t/make-pathlib-extensible/3428/196

Linked PRs

Activity

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

    stdlibStandard Library Python modules in the Lib/ directorytopic-pathlibtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions