Skip to content

pathlib ABCs: add protocols for supporting types #127456

Closed
@barneygale

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions