forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pythonGH-127456: pathlib ABCs: add protocol for path parser (python#1…
…27494) Change the default value of `PurePathBase.parser` from `ParserBase()` to `posixpath`. As a result, user subclasses of `PurePathBase` and `PathBase` use POSIX path syntax by default, which is very often desirable. Move `pathlib._abc.ParserBase` to `pathlib._types.Parser`, and convert it to a runtime-checkable protocol. Co-authored-by: Bénédikt Tran <[email protected]>
- Loading branch information
1 parent
e85f2f1
commit 5c89adf
Showing
3 changed files
with
32 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
""" | ||
Protocols for supporting classes in pathlib. | ||
""" | ||
from typing import Protocol, runtime_checkable | ||
|
||
|
||
@runtime_checkable | ||
class Parser(Protocol): | ||
"""Protocol for path parsers, which do low-level path manipulation. | ||
Path parsers provide a subset of the os.path API, specifically those | ||
functions needed to provide PurePathBase functionality. Each PurePathBase | ||
subclass references its path parser via a 'parser' class attribute. | ||
""" | ||
|
||
sep: str | ||
def join(self, path: str, *paths: str) -> str: ... | ||
def split(self, path: str) -> tuple[str, str]: ... | ||
def splitdrive(self, path: str) -> tuple[str, str]: ... | ||
def splitext(self, path: str) -> tuple[str, str]: ... | ||
def normcase(self, path: str) -> str: ... | ||
def isabs(self, path: str) -> bool: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters