Thanks to visit codestin.com
Credit goes to github.com

Skip to content

pathlib ABCs: prune PathBase interface #127381

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

Closed
barneygale opened this issue Nov 29, 2024 · 3 comments
Closed

pathlib ABCs: prune PathBase interface #127381

barneygale opened this issue Nov 29, 2024 · 3 comments
Labels
stdlib Python modules in the Lib dir topic-pathlib

Comments

@barneygale
Copy link
Contributor

barneygale commented Nov 29, 2024

It's time to make some difficult decisions about which methods deserve to stay in the pathlib._abc.PathBase interface, and which ought to be made pathlib.Path-only. Guidelines:

  • Compare to zipfile.Path and os.DirEntry; don't evict shared methods.
  • Include abstract methods only for the most basic functionality common to all virtual filesystems
  • Include concrete methods only when they combine abstract methods to produce widely useful functionality

Linked PRs

@barneygale barneygale added topic-pathlib type-feature A feature request or enhancement stdlib Python modules in the Lib dir and removed type-feature A feature request or enhancement labels Nov 29, 2024
barneygale added a commit to barneygale/cpython that referenced this issue Nov 29, 2024
Remove the `PathBase.lstat()` method, which is a trivial variation of
`stat()`.

No user-facing changes because the pathlib ABCs are still private.
barneygale added a commit to barneygale/cpython that referenced this issue Nov 29, 2024
barneygale added a commit that referenced this issue Nov 29, 2024
Remove the `PathBase.lstat()` method, which is a trivial variation of
`stat()`.

No user-facing changes because the pathlib ABCs are still private.
barneygale added a commit to barneygale/cpython that referenced this issue Nov 29, 2024
These classmethods presume that the user has retained the original
`__init__()` signature, which may not be the case. Also, many virtual
filesystems don't provide current or home directories.
barneygale added a commit that referenced this issue Nov 30, 2024
These classmethods presume that the user has retained the original
`__init__()` signature, which may not be the case. Also, many virtual
filesystems don't provide current or home directories.
picnixz pushed a commit to picnixz/cpython that referenced this issue Dec 2, 2024
Remove the `PathBase.lstat()` method, which is a trivial variation of
`stat()`.

No user-facing changes because the pathlib ABCs are still private.
picnixz pushed a commit to picnixz/cpython that referenced this issue Dec 2, 2024
…ython#127427)

These classmethods presume that the user has retained the original
`__init__()` signature, which may not be the case. Also, many virtual
filesystems don't provide current or home directories.
barneygale added a commit to barneygale/cpython that referenced this issue Dec 5, 2024
…e()`

These methods are obviated by `PathBase.move()`, which can move directories
and supports any `PathBase` object as a target.
barneygale added a commit that referenced this issue Dec 6, 2024
…127658)

These methods are obviated by `PathBase.move()`, which can move directories
and supports any `PathBase` object as a target.
barneygale added a commit to barneygale/cpython that referenced this issue Dec 6, 2024
…ute()`

Remove our implementation of POSIX path resolution in `PathBase.resolve()`.
This functionality is rather fragile and isn't necessary in most cases. It
depends on `PathBase.stat()`, which we're looking to remove.

Also remove `PathBase.absolute()`. Many legitimate virtual filesystems lack
the notion of a 'current directory', so it's wrong to include in the basic
interface.
barneygale added a commit to barneygale/cpython that referenced this issue Dec 6, 2024
… `is_*()`

Remove `PathBase.samefile()`, which is fairly specific to the local FS, and
relies on `stat()`, which we're aiming to remove from `PathBase`.

Also remove `PathBase.is_mount()`, `is_junction()`, `is_block_device()`,
`is_char_device()`, `is_fifo()` and `is_socket()`. These rely on POSIX
file type numbers that we're aiming to remove from the `PathBase` API.
barneygale added a commit that referenced this issue Dec 6, 2024
…#127707)

Remove our implementation of POSIX path resolution in `PathBase.resolve()`.
This functionality is rather fragile and isn't necessary in most cases. It
depends on `PathBase.stat()`, which we're looking to remove.

Also remove `PathBase.absolute()`. Many legitimate virtual filesystems lack
the notion of a 'current directory', so it's wrong to include in the basic
interface.
barneygale added a commit to barneygale/cpython that referenced this issue Dec 6, 2024
barneygale added a commit to barneygale/cpython that referenced this issue Dec 7, 2024
…ethods

Remove the following methods from `pathlib._abc.PathBase`:

- `expanduser()`
- `hardlink_to()`
- `touch()`
- `chmod()`
- `lchmod()`
- `owner()`
- `group()`
- `from_uri()`
- `as_uri()`

These operations aren't regularly supported in virtual filesystems, so they
don't win a place in the `PathBase` interface. (Some of them probably don't
deserve a place in `Path` :P.) They're quasi-abstract (except `lchmod()`),
and they're not called by other `PathBase` methods.
barneygale added a commit to barneygale/cpython that referenced this issue Dec 8, 2024
Virtual filesystems don't always make a distinction between deleting files
and empty directories, and sometimes support deleting non-empty directories
in a single operation. Here we remove `PathBase.unlink()` and `rmdir()`,
leaving `_delete()` as the sole deletion method, now made abstract. I hope
to drop the underscore prefix later on.
barneygale added a commit that referenced this issue Dec 8, 2024
…27736)

Virtual filesystems don't always make a distinction between deleting files
and empty directories, and sometimes support deleting non-empty directories
in a single operation. Here we remove `PathBase.unlink()` and `rmdir()`,
leaving `_delete()` as the sole deletion method, now made abstract. I hope
to drop the underscore prefix later on.
barneygale added a commit to barneygale/cpython that referenced this issue Dec 8, 2024
barneygale added a commit to barneygale/cpython that referenced this issue Dec 8, 2024
ebonnal pushed a commit to ebonnal/cpython that referenced this issue Jan 12, 2025
Remove the `PathBase.lstat()` method, which is a trivial variation of
`stat()`.

No user-facing changes because the pathlib ABCs are still private.
ebonnal pushed a commit to ebonnal/cpython that referenced this issue Jan 12, 2025
…ython#127427)

These classmethods presume that the user has retained the original
`__init__()` signature, which may not be the case. Also, many virtual
filesystems don't provide current or home directories.
barneygale added a commit to barneygale/cpython that referenced this issue Jan 21, 2025
Unlike `ReadablePath.[r]glob()` and `JoinablePath.full_match()`, the
`JoinablePath.match()` method doesn't support the recursive wildcard `**`,
and matches from the right when a fully relative pattern is given. These
quirks means its probably unsuitable for inclusion in the pathlib ABCs,
especially given `full_match()` handles the same use case.
@barneygale
Copy link
Contributor Author

barneygale commented Jan 21, 2025

Re-opening to remove JoinablePath.match()

@barneygale barneygale reopened this Jan 21, 2025
barneygale added a commit that referenced this issue Jan 28, 2025
Unlike `ReadablePath.[r]glob()` and `JoinablePath.full_match()`, the
`JoinablePath.match()` method doesn't support the recursive wildcard `**`,
and matches from the right when a fully relative pattern is given. These
quirks means its probably unsuitable for inclusion in the pathlib ABCs,
especially given `full_match()` handles the same use case.
barneygale added a commit to barneygale/cpython that referenced this issue Feb 16, 2025
Remove `ReadablePath.rglob()` from the private pathlib ABCs. This method is
a trivial wrapper around `glob()` and easily replaced.
@barneygale
Copy link
Contributor Author

Once more with feeling...

@barneygale barneygale reopened this Feb 16, 2025
barneygale added a commit that referenced this issue Feb 17, 2025
Remove `ReadablePath.rglob()` from the private pathlib ABCs. This method is
a trivial wrapper around `glob()` and easily replaced.
barneygale added a commit to barneygale/cpython that referenced this issue Feb 24, 2025
…_*()`

Remove `ReadablePath` methods duplicated by `ReadablePath.info`. To be
specific, we remove `exists()`, `is_dir()`, `is_file()` and `is_symlink()`.
barneygale added a commit to barneygale/cpython that referenced this issue Feb 26, 2025
barneygale added a commit to barneygale/cpython that referenced this issue Feb 26, 2025
Remove the *mode*, *parents* and *exist_ok* arguments from
`WritablePath.mkdir()`. These arguments imply support for POSIX permissions
and checking for preexistence of the path or its parents, but subclasses of
`WritablePath` may not have these capabilities.
barneygale added a commit to barneygale/cpython that referenced this issue Feb 28, 2025
barneygale added a commit that referenced this issue Mar 1, 2025
…130520)

Remove `ReadablePath` methods duplicated by `ReadablePath.info`. To be
specific, we remove `exists()`, `is_dir()`, `is_file()` and `is_symlink()`.

The public `Path` class retains these methods.
barneygale added a commit that referenced this issue Mar 1, 2025
…0611)

Remove the *mode*, *parents* and *exist_ok* arguments from
`WritablePath.mkdir()`. These arguments imply support for POSIX permissions
and checking for preexistence of the path or its parents, but subclasses of
`WritablePath` may not have these capabilities.

The public `Path.mkdir()` method retains these arguments.
barneygale added a commit to barneygale/cpython that referenced this issue Mar 9, 2025
Remove the *case_sensitive* argument from `_JoinablePath.full_match()` and
`_ReadablePath.glob()`. Using a non-native case sensitivity forces the use
of "case-pedantic" globbing, where we `iterdir()` even for non-wildcard
pattern segments. But it's hard to know when to enable this mode, as
case-sensitivity can vary by directory, so `_PathParser.normcase()` doesn't
always give the full picture. The `Path.glob()` implementation is forced to
make an educated guess, but we can avoid the issue in the ABCs by dropping
the *case_sensitive* argument.

(I probably shouldn't have added these arguments in `PurePath` and `Path`
in the first place!)

Also drop support for `_ReadablePath.glob(recurse_symlinks=False)`, which
makes recursive globbing much slower.
@barneygale barneygale reopened this Mar 9, 2025
barneygale added a commit that referenced this issue Mar 10, 2025
Remove the *case_sensitive* argument from `_JoinablePath.full_match()` and
`_ReadablePath.glob()`. Using a non-native case sensitivity forces the use
of "case-pedantic" globbing, where we `iterdir()` even for non-wildcard
pattern segments. But it's hard to know when to enable this mode, as
case-sensitivity can vary by directory, so `_PathParser.normcase()` doesn't
always give the full picture. The `Path.glob()` implementation is forced to
make an educated guess, but we can avoid the issue in the ABCs by dropping
the *case_sensitive* argument.

(I probably shouldn't have added these arguments in `PurePath` and `Path`
in the first place!)

Also drop support for `_ReadablePath.glob(recurse_symlinks=False)`, which
makes recursive globbing much slower.
seehwan pushed a commit to seehwan/cpython that referenced this issue Apr 16, 2025
…_*()` (python#130520)

Remove `ReadablePath` methods duplicated by `ReadablePath.info`. To be
specific, we remove `exists()`, `is_dir()`, `is_file()` and `is_symlink()`.

The public `Path` class retains these methods.
seehwan pushed a commit to seehwan/cpython that referenced this issue Apr 16, 2025
python#130611)

Remove the *mode*, *parents* and *exist_ok* arguments from
`WritablePath.mkdir()`. These arguments imply support for POSIX permissions
and checking for preexistence of the path or its parents, but subclasses of
`WritablePath` may not have these capabilities.

The public `Path.mkdir()` method retains these arguments.
seehwan pushed a commit to seehwan/cpython that referenced this issue Apr 16, 2025
…on#131024)

Remove the *case_sensitive* argument from `_JoinablePath.full_match()` and
`_ReadablePath.glob()`. Using a non-native case sensitivity forces the use
of "case-pedantic" globbing, where we `iterdir()` even for non-wildcard
pattern segments. But it's hard to know when to enable this mode, as
case-sensitivity can vary by directory, so `_PathParser.normcase()` doesn't
always give the full picture. The `Path.glob()` implementation is forced to
make an educated guess, but we can avoid the issue in the ABCs by dropping
the *case_sensitive* argument.

(I probably shouldn't have added these arguments in `PurePath` and `Path`
in the first place!)

Also drop support for `_ReadablePath.glob(recurse_symlinks=False)`, which
makes recursive globbing much slower.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir topic-pathlib
Projects
None yet
Development

No branches or pull requests

1 participant