GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-110109: Add `pathlib._PurePathBase` by barneygale · Pull Request #110670 · python/cpython

Conversation

@barneygale

@barneygale barneygale commented Oct 11, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Add private pathlib._PurePathBase class: a private superclass of both PurePath and _PathBase. Unlike PurePath, it does not define any of these special methods: __fspath__, __bytes__, __reduce__, __hash__, __eq__, __lt__, __le__, __gt__, __ge__. Its initializer and path joining methods accept only strings, not os.PathLike objects more broadly.

This is important for supporting virtual paths: user subclasses of _PathBase that provide access to archive files, FTP servers, etc. In these classes, the above methods should be implemented by users only as appropriate, with due consideration for the hash/equality of any backing objects, such as file objects or sockets.

  • Issue: User-defined virtual path objects #110109

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

edgarrmondragon reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@barneygale
pythonGH-110109: Add pathlib._PurePathBase
41a8de4
Add private `pathlib._PurePathBase` class: a private superclass of both
`PurePath` and `_PathBase`. Unlike `PurePath`, it does not define any of
these special methods: `__fspath__`, `__bytes__`, `__reduce__`, `__hash__`,
`__eq__`, `__lt__`, `__le__`, `__gt__`, `__ge__`.

This is important for supporting *virtual paths*: user subclasses of
`_PathBase` that provide access to archive files, FTP servers, etc. In
these classes, the above methods should be implemented by users only as
appropriate, with due consideration for the hash/equality of any backing
objects, such as file objects or sockets.
@barneygale barneygale added the topic-pathlib label Oct 11, 2023
@bedevere-app bedevere-app Bot added the awaiting review label Oct 11, 2023
@bedevere-app bedevere-app Bot mentioned this pull request Oct 11, 2023
User-defined virtual path objects #110109
Closed
8 tasks done
@barneygale

barneygale commented Oct 11, 2023

Copy link
Copy Markdown
Contributor Author

FYI @AlexWaygood. We avoided adding this class previously with your clever suggestion to set __fspath__ and __bytes__ to None in PathBase, and then restore their values in Path. (see #106082, #106337).

But I'm increasingly convinced that this extra class is needed after all - there are too many PurePath magic methods which shouldn't be inherited by PathBase. Hence this PR adds a new superclass.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@barneygale

barneygale commented Oct 11, 2023

Copy link
Copy Markdown
Contributor Author

An inheritance diagram:

image

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@barneygale barneygale mentioned this pull request Oct 13, 2023
maintainership & project lead jazzband/pathlib2#70
Open
barneygale added 3 commits October 28, 2023 22:27
@barneygale
Merge branch 'main' into pythongh-110109-purepathbase
6489e4b
@barneygale
Fix walk test
fd6fd0b
@barneygale
Merge branch 'main' into pythongh-110109-purepathbase
6c742ed
@barneygale

barneygale commented Nov 13, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Quite a lot of this patch is re-ordering methods. I've split that stuff off into a preparatory PR, which will help make this PR easier to review:

#112012

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@barneygale barneygale mentioned this pull request Nov 13, 2023
GH-110109: Churn pathlib.PurePath methods #112012
Merged
@barneygale
barneygale requested review from JelleZijlstra and removed request for JelleZijlstra November 13, 2023 01:54
barneygale added 7 commits November 13, 2023 17:25
@barneygale
Merge branch 'main' into pythongh-110109-purepathbase
3f56662
@barneygale
Merge branch 'main' into pythongh-110109-purepathbase
94973de
@barneygale
Run tests for OS-specific pure paths against concrete classes
6d9985a
@barneygale
Merge branch 'main' into pythongh-110109-purepathbase
7e1a880
@barneygale
Match superclass order in tests
1f9a480
@barneygale
More MRO adjustments
6dd0208
@barneygale
Merge branch 'main' into pythongh-110109-purepathbase
a9eeaf4
@barneygale
barneygale requested a review from AlexWaygood November 25, 2023 14:48
barneygale added 3 commits November 26, 2023 18:31
@barneygale
Add note about string arguments.
73777f2
@barneygale
Make adjustments to tests more consistent
9977fe8
@barneygale
Me fail English? That's unpossible!
cacc0f3
@barneygale

barneygale commented Nov 28, 2023

Copy link
Copy Markdown
Contributor Author

Once this lands, I plan to:

  1. Move _PurePathBase and _PathBase into a new pathlib._abc module (likewise their tests)
  2. Copy-paste that code into a pathlib_abc PyPI package, dropping the class underscore prefixes
  3. Engage with the community and iterate on pathlib_abc (regularly syncing changes back to CPython) for at least a few months, more likely a couple years
  4. Drop the class underscore prefixes in CPython; make pathlib_abc a backport-only package.

It's going to be a while before PurePathBase sees official public release in CPython, so I reckon we don't need to get its interface perfect in this PR. Hopefully that makes it less intimidating to review.

ktdreyer reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@barneygale
Merge branch 'main' into pythongh-110109-purepathbase
5a72500
@barneygale
barneygale removed the request for review from AlexWaygood December 8, 2023 17:29
@barneygale

barneygale commented Dec 8, 2023

Copy link
Copy Markdown
Contributor Author

Given that this change is blocking work on pathlib ABCs, and should have no observable effects on any public APIs, I'm going to merge it without waiting any longer for review.

If that doesn't seem right to anyone, please let me know and I can revert it. I'm never quite sure where to draw the line on these things.

AlexWaygood reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@barneygale
barneygale merged commit 76929fd into python:main Dec 8, 2023
@bedevere-app bedevere-app Bot removed the awaiting review label Dec 8, 2023
@barneygale barneygale mentioned this pull request Dec 9, 2023
Performance regression in pathlib path instantiation #112906
Closed
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
@barneygale @aisk
pythonGH-110109: Add pathlib._PurePathBase (python#110670)
35c0618
Add private `pathlib._PurePathBase` class: a private superclass of both `PurePath` and `_PathBase`. Unlike `PurePath`, it does not define any of these special methods: `__fspath__`, `__bytes__`, `__reduce__`, `__hash__`, `__eq__`, `__lt__`, `__le__`, `__gt__`, `__ge__`. Its initializer and path joining methods accept only strings, not os.PathLike objects more broadly.

This is important for supporting *virtual paths*: user subclasses of `_PathBase` that provide access to archive files, FTP servers, etc. In these classes, the above methods should be implemented by users only as appropriate, with due consideration for the hash/equality of any backing objects, such as file objects or sockets.
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
@barneygale @Glyphack
pythonGH-110109: Add pathlib._PurePathBase (python#110670)
b794582
Add private `pathlib._PurePathBase` class: a private superclass of both `PurePath` and `_PathBase`. Unlike `PurePath`, it does not define any of these special methods: `__fspath__`, `__bytes__`, `__reduce__`, `__hash__`, `__eq__`, `__lt__`, `__le__`, `__gt__`, `__ge__`. Its initializer and path joining methods accept only strings, not os.PathLike objects more broadly.

This is important for supporting *virtual paths*: user subclasses of `_PathBase` that provide access to archive files, FTP servers, etc. In these classes, the above methods should be implemented by users only as appropriate, with due consideration for the hash/equality of any backing objects, such as file objects or sockets.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

topic-pathlib

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@barneygale
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.