Skip to content
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

pathlib ABCs: prune PathBase interface #127381

Open
barneygale opened this issue Nov 29, 2024 · 2 comments
Open

pathlib ABCs: prune PathBase interface #127381

barneygale opened this issue Nov 29, 2024 · 2 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
barneygale added a commit to barneygale/cpython that referenced this issue Dec 22, 2024
barneygale added a commit to barneygale/cpython that referenced this issue Dec 29, 2024
Remove the `PathBase.stat()` method. Its use of the `os.stat_result` API,
with its 10 mandatory fields and low-level types, makes it a poor fit for
virtual filesystems.

We'll look to add a `PathBase.info` attribute later - see pythonGH-125413.
barneygale added a commit that referenced this issue Dec 29, 2024
Remove the `PathBase.stat()` method. Its use of the `os.stat_result` API,
with its 10 mandatory fields and low-level types, makes it an awkward fit
for virtual filesystems.

We'll look to add a `PathBase.info` attribute later - see GH-125413.
barneygale added a commit to barneygale/cpython that referenced this issue Dec 29, 2024
barneygale added a commit that referenced this issue Dec 29, 2024
)

Remove `PurePathBase.relative_to()` and `is_relative_to()` because they
don't account for *other* being an entirely different kind of path, and
they can't use `__eq__()` because it's not on the `PurePathBase` interface.

Remove `PurePathBase.drive`, `root`, `is_absolute()` and `as_posix()`.
These are all too specific to local filesystems.
barneygale added a commit to barneygale/cpython that referenced this issue Dec 29, 2024
…o()`

These methods combine `_delete()` and `copy()`, but `_delete()` isn't part
of the public interface, and it's unlikely to be added until the pathlib
ABCs are made official, or perhaps even later.
barneygale added a commit to barneygale/cpython that referenced this issue Dec 29, 2024
…o()`

These methods combine `_delete()` and `copy()`, but `_delete()` isn't part
of the public interface, and it's unlikely to be added until the pathlib
ABCs are made official, or perhaps even later.
barneygale added a commit that referenced this issue Jan 4, 2025
…128337)

These methods combine `_delete()` and `copy()`, but `_delete()` isn't part
of the public interface, and it's unlikely to be added until the pathlib
ABCs are made official, or perhaps even later.
@barneygale
Copy link
Contributor Author

Pruning is done! There are a few more changes planned:

  • Rename PurePathBase to JoinablePath
  • Split PathBase into ReadablePath and WritablePath
  • Add PathBase.status (see Expose os.DirEntry objects from pathlib #125413)
  • Subclass abc.ABC
  • Make JoinablePath.parser abstract
  • Figure out what to do with open()

hugovk pushed a commit to hugovk/cpython that referenced this issue Jan 4, 2025
…o()` (python#128337)

These methods combine `_delete()` and `copy()`, but `_delete()` isn't part
of the public interface, and it's unlikely to be added until the pathlib
ABCs are made official, or perhaps even later.
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Jan 6, 2025
…o()` (python#128337)

These methods combine `_delete()` and `copy()`, but `_delete()` isn't part
of the public interface, and it's unlikely to be added until the pathlib
ABCs are made official, or perhaps even later.
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Jan 8, 2025
Remove the `PathBase.lstat()` method, which is a trivial variation of
`stat()`.

No user-facing changes because the pathlib ABCs are still private.
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Jan 8, 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.
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Jan 8, 2025
…e()` (python#127658)

These methods are obviated by `PathBase.move()`, which can move directories
and supports any `PathBase` object as a target.
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Jan 8, 2025
…ute()` (python#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.
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Jan 8, 2025
…)` (python#127736)

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.
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Jan 8, 2025
… `is_*()` (python#127709)

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.
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Jan 8, 2025
…ethods (python#127714)

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.
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Jan 8, 2025
Remove the `PathBase.stat()` method. Its use of the `os.stat_result` API,
with its 10 mandatory fields and low-level types, makes it an awkward fit
for virtual filesystems.

We'll look to add a `PathBase.info` attribute later - see pythonGH-125413.
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Jan 8, 2025
…python#127853)

Remove `PurePathBase.relative_to()` and `is_relative_to()` because they
don't account for *other* being an entirely different kind of path, and
they can't use `__eq__()` because it's not on the `PurePathBase` interface.

Remove `PurePathBase.drive`, `root`, `is_absolute()` and `as_posix()`.
These are all too specific to local filesystems.
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Jan 8, 2025
…o()` (python#128337)

These methods combine `_delete()` and `copy()`, but `_delete()` isn't part
of the public interface, and it's unlikely to be added until the pathlib
ABCs are made official, or perhaps even later.
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
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