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: remove or namespace private attributes #127807

Closed
barneygale opened this issue Dec 11, 2024 · 1 comment
Closed

pathlib ABCs: remove or namespace private attributes #127807

barneygale opened this issue Dec 11, 2024 · 1 comment
Labels
stdlib Python modules in the Lib dir topic-pathlib

Comments

@barneygale
Copy link
Contributor

barneygale commented Dec 11, 2024

@encukou pointed out:

I see there's currently no distinction between pathlib-internal attribute names and names that are free for third-party subclasses to use.
Should there be a stronger namespace for these, like _pathlib_sep, _pathlib_globber & _pathlib_stack?
Or should _sep & co. be documented so users know to not override them?

PurePathBase and PathBase have ~10 private attributes for facilitating copying, ~3 for matching and globbing, and ~3 more for miscellaneous purposes. We should try to eliminate as many as possible, and namespace the rest (e.g. under _pathlib_)

Linked PRs

@barneygale barneygale added stdlib Python modules in the Lib dir topic-pathlib labels Dec 11, 2024
barneygale added a commit to barneygale/cpython that referenced this issue Dec 11, 2024
…ted class

Move 9 private `PathBase` attributes and methods into a new `CopyWorker`
class. Change `PathBase.copy` from a method to a `CopyWorker` instance.

The methods remain private in the `CopyWorker` class. In future we might
make some/all of them public so that user subclasses of `PathBase` can
customize the copying process (in particular reading/writing of metadata,)
but we'd need to make `PathBase` public first.
barneygale added a commit to barneygale/cpython that referenced this issue Dec 11, 2024
…ted class

Move 9 private `PathBase` attributes and methods into a new `CopyWorker`
class. Change `PathBase.copy` from a method to a `CopyWorker` instance.

The methods remain private in the `CopyWorker` class. In future we might
make some/all of them public so that user subclasses of `PathBase` can
customize the copying process (in particular reading/writing of metadata,)
but we'd need to make `PathBase` public first.
barneygale added a commit to barneygale/cpython that referenced this issue Dec 12, 2024
From `PurePathBase` delete `_stack` and `_pattern_str`, and from `PathBase`
delete `_glob_selector`.
barneygale added a commit to barneygale/cpython that referenced this issue Dec 12, 2024
This method helped us customise the `UnsupportedOperation` message
depending on the type. But we're aiming to make `PathBase` a proper ABC
soon, so `NotImplementedError` is the right exception to raise there.
barneygale added a commit to barneygale/cpython that referenced this issue Dec 12, 2024
This method helped us customise the `UnsupportedOperation` message
depending on the type. But we're aiming to make `PathBase` a proper ABC
soon, so `NotImplementedError` is the right exception to raise there.
barneygale added a commit to barneygale/cpython that referenced this issue Dec 12, 2024
This method helped us customise the `UnsupportedOperation` message
depending on the type. But we're aiming to make `PathBase` a proper ABC
soon, so `NotImplementedError` is the right exception to raise there.
barneygale added a commit that referenced this issue Dec 12, 2024
This method helped us customise the `UnsupportedOperation` message
depending on the type. But we're aiming to make `PathBase` a proper ABC
soon, so `NotImplementedError` is the right exception to raise there.
barneygale added a commit to barneygale/cpython that referenced this issue Dec 12, 2024
Remove the `PurePathBase` initializer, and make `with_segments()` and
`__str__()` abstract. This allows us to drop the `_raw_paths` attribute,
and also the `Parser.join()` protocol method.
barneygale added a commit to barneygale/cpython that referenced this issue Dec 22, 2024
barneygale added a commit that referenced this issue Dec 22, 2024
Remove the `PurePathBase` initializer, and make `with_segments()` and
`__str__()` abstract. This allows us to drop the `_raw_paths` attribute,
and also the `Parser.join()` protocol method.
barneygale added a commit to barneygale/cpython that referenced this issue Dec 22, 2024
barneygale added a commit that referenced this issue Dec 22, 2024
From `PurePathBase` delete `_globber`, `_stack` and `_pattern_str`, and
from `PathBase` delete `_glob_selector`. This helps avoid an unpleasant
surprise for a users who try to use these names.
barneygale added a commit to barneygale/cpython that referenced this issue Dec 22, 2024
barneygale added a commit that referenced this issue Dec 22, 2024
…ass (#127810)

Move 9 private `PathBase` attributes and methods into a new `CopyWorker`
class. Change `PathBase.copy` from a method to a `CopyWorker` instance.

The methods remain private in the `CopyWorker` class. In future we might
make some/all of them public so that user subclasses of `PathBase` can
customize the copying process (in particular reading/writing of metadata,)
but we'd need to make `PathBase` public first.
@barneygale
Copy link
Contributor Author

This is done, with two exceptions:

  1. PathBase._scandir() will be removed as part of Expose os.DirEntry objects from pathlib #125413
  2. PathBase._delete() will be made public some time, hopefully.

srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Dec 23, 2024
…on#127883)

Remove the `PurePathBase` initializer, and make `with_segments()` and
`__str__()` abstract. This allows us to drop the `_raw_paths` attribute,
and also the `Parser.join()` protocol method.
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Dec 23, 2024
…n#127851)

From `PurePathBase` delete `_globber`, `_stack` and `_pattern_str`, and
from `PathBase` delete `_glob_selector`. This helps avoid an unpleasant
surprise for a users who try to use these names.
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Dec 23, 2024
…ted class (python#127810)

Move 9 private `PathBase` attributes and methods into a new `CopyWorker`
class. Change `PathBase.copy` from a method to a `CopyWorker` instance.

The methods remain private in the `CopyWorker` class. In future we might
make some/all of them public so that user subclasses of `PathBase` can
customize the copying process (in particular reading/writing of metadata,)
but we'd need to make `PathBase` public first.
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