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-89812: Add `pathlib._PurePathExt` by barneygale · Pull Request #104810 · python/cpython

Conversation

@barneygale

@barneygale barneygale commented May 23, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Move __fspath__(), __bytes__() and as_uri() methods from PurePath to a new _PurePathExt subclass. This new subclass is inherited by PurePosixPath, PureWindowsPath and Path.

Because PurePath isn't directly instantiatable (you get a PurePosixPath or PureWindowsPath instance back), this shouldn't change user-facing behaviour.

The methods must not be inherited future tarfile.TarPath and pathlib.AbstractPath classes, which will subclass PurePath.

  • Discussion: https://discuss.python.org/t/make-pathlib-extensible/3428/94
  • Issue: Add tarfile.TarPath #89812

Sorry, something went wrong.

Uh oh!

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

All reactions
@barneygale
pythonGH-89812: Add pathlib._LexicalPath
81e301b
This internal class excludes the `__fspath__()`, `__bytes__()` and
`as_uri()` methods, which must not be inherited by a future
`tarfile.TarPath` class.
@barneygale barneygale added skip news topic-pathlib labels May 23, 2023
@bedevere-bot bedevere-bot added the awaiting core review label May 23, 2023
@bedevere-bot bedevere-bot mentioned this pull request May 23, 2023
Add tarfile.TarPath #89812
Open
@barneygale
barneygale requested a review from CAM-Gerlach May 23, 2023 19:44
@barneygale
Rename _LexicalPath --> _BasePurePath
ace5824
@barneygale barneygale changed the title GH-89812: Add pathlib._LexicalPath GH-89812: Add pathlib._BasePurePath May 23, 2023
@barneygale

barneygale commented May 24, 2023

Copy link
Copy Markdown
Contributor Author

The test naming is pretty janky. #104829 will help.

All reactions

Sorry, something went wrong.

Uh oh!

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

merwok
merwok reviewed May 24, 2023
View reviewed changes
Comment thread Lib/pathlib.py Resolved

Uh oh!

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

merwok
merwok reviewed May 24, 2023
View reviewed changes
Comment thread Lib/pathlib.py Resolved

Uh oh!

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

merwok
merwok reviewed May 24, 2023
View reviewed changes
Comment thread Lib/pathlib.py Resolved

Uh oh!

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

@barneygale
Document __bytes__ in PurePath docstring
d1b23c8
merwok
merwok reviewed May 24, 2023
View reviewed changes
Comment thread Lib/pathlib.py Resolved

Uh oh!

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

Comment thread Lib/pathlib.py Resolved

Uh oh!

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

Comment thread Lib/pathlib.py Resolved

Uh oh!

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

Comment thread Lib/pathlib.py Resolved

Uh oh!

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

barneygale and others added 2 commits May 24, 2023 16:04
@barneygale @merwok
Apply suggestions from code review
115002a
Co-authored-by: Éric <[email protected]>
@barneygale
Revert "Document __bytes__ in PurePath docstring"
f257e48
This reverts commit d1b23c8.
AlexWaygood
AlexWaygood reviewed May 24, 2023
View reviewed changes
Comment thread Lib/pathlib.py Resolved

Uh oh!

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

barneygale and others added 2 commits May 24, 2023 17:36
@barneygale @AlexWaygood
Update Lib/pathlib.py
68d2891
Co-authored-by: Alex Waygood <[email protected]>
@barneygale
Subclass from os.PathLike
458c33d
AlexWaygood
AlexWaygood reviewed May 24, 2023
View reviewed changes
Comment thread Lib/os.py Resolved

Uh oh!

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

@barneygale
Add news blurb
6d9a1a2
@barneygale barneygale removed the skip news label May 24, 2023
@barneygale barneygale mentioned this pull request May 24, 2023
os.PathLike is missing __slots__ #104898
Closed
barneygale added 2 commits May 24, 2023 22:53
@barneygale
Revert "Subclass from os.PathLike"
bd23782
This reverts commit 458c33d.
@barneygale
Revert "Add news blurb"
a69417f
This reverts commit 6d9a1a2.
@barneygale barneygale added the skip news label May 24, 2023
@barneygale
Merge branch 'main' into pythongh-89812-add-lexicalpath
45f6bd3
@barneygale barneygale mentioned this pull request May 25, 2023
GH-89812: Clean up pathlib tests. #104829
Merged
barneygale
barneygale commented May 29, 2023
View reviewed changes
Comment thread Lib/test/test_pathlib.py Resolved

Uh oh!

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

@barneygale
Merge branch 'main' into pythongh-89812-add-lexicalpath
1e24f80
@barneygale

barneygale commented Jun 7, 2023

Copy link
Copy Markdown
Contributor Author

Would anyone be willing to review #104829? It blocks this PR. (please and thank you!)

All reactions

Sorry, something went wrong.

Uh oh!

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

@barneygale
barneygale marked this pull request as draft June 7, 2023 20:26
@bedevere-bot bedevere-bot removed the awaiting core review label Jun 7, 2023
barneygale added 3 commits June 12, 2023 15:53
@barneygale
Merge branch 'main' into pythongh-89812-add-lexicalpath
70d81d6
@barneygale
Merge branch 'main' into pythongh-89812-add-lexicalpath
7e7b5d4
@barneygale
Fix missed isinstance() call.
98e30d4
@barneygale
barneygale marked this pull request as ready for review June 14, 2023 16:12
@bedevere-bot bedevere-bot added the awaiting core review label Jun 14, 2023
@barneygale

barneygale commented Jun 14, 2023

Copy link
Copy Markdown
Contributor Author

#104829 has landed, so test naming should be much improved! Think this is ready for review again.

All reactions

Sorry, something went wrong.

Uh oh!

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

@barneygale
barneygale requested review from AlexWaygood and merwok June 14, 2023 18:02
barneygale added 2 commits June 15, 2023 02:45
@barneygale
Merge branch 'main' into pythongh-89812-add-lexicalpath
8d12e06
@barneygale
Drop methods from PurePath itself, as it cannot be instantiated.
e36eb74
@barneygale barneygale changed the title GH-89812: Add pathlib._BasePurePath GH-89812: Add pathlib._PurePathExt Jun 22, 2023
@barneygale

barneygale commented Jun 22, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

I've revised the implementation such that the methods are actually removed from PurePath. This will allow our future AbstractPath class to inherit PurePath, as it should conceptually:

image

(Contrast this with the earlier proposed hierarchy where PurePath and AbstractPath are siblings.

The methods are moved to a new _PurePathExt class, which is inherited by PurePosixPath, PureWindowsPath and Path.

This change will not be visible to users who try to instantiate PurePath, because they'll always get a PurePosixPath or PureWindowsPath instance back.

It will be visible to users who subclass PurePath, but that has only just become possible in 3.12. As such I think it's worth backporting this into 3.12 for consistency.

All reactions

Sorry, something went wrong.

Uh oh!

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

@barneygale

barneygale commented Jun 22, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Here's a version of the diagram that includes the private _PurePathExt class. The diagram in the post above excluded it in order to show the public view of the class hierarchy.

image

All reactions

Sorry, something went wrong.

Uh oh!

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

@merwok

merwok commented Jun 23, 2023

Copy link
Copy Markdown
Member

Just a note that I’m meditating on https://hynek.me/articles/python-subclassing-redux/ and linked articles at the moment and wondering if controlling subclass explosion in pathlib should be a guideline 🙂

All reactions

Sorry, something went wrong.

Uh oh!

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

@barneygale

barneygale commented Jun 23, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Oh I totally agree. I'd prefer to add only pathlib.AbstractPath, but I'm prevented by the fact that PurePath has an __fspath__() method :)

And if I were to do pathlib over again, I'd scrap the *WindowsPath and *PosixPath classes. That could be controlled by an argument to the PurePath initialiser instead. Oh well...

All reactions

Sorry, something went wrong.

Uh oh!

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

@barneygale
barneygale marked this pull request as draft June 23, 2023 11:57
@bedevere-bot bedevere-bot removed the awaiting core review label Jun 23, 2023
@barneygale

barneygale commented Jun 23, 2023

Copy link
Copy Markdown
Contributor Author

I've converted this back to a draft as I'm still in two minds about how to implement this. It's possible I'll add _AbstractPath into this PR, or close this PR and log another, or something else. Sorry for the noise

merwok 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 added 3 commits June 23, 2023 17:26
@barneygale
Move as_uri() back
0ea24cc
@barneygale
Adjust docs
342e64b
@barneygale
Add tests
90bc6b3
@barneygale

barneygale commented Jun 23, 2023

Copy link
Copy Markdown
Contributor Author

Friendship ended with #104810, now #106043 is my best friend.

CAM-Gerlach reacted with laugh emoji
All reactions
  • 😄 1 reaction

Sorry, something went wrong.

Uh oh!

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

@barneygale barneygale closed this Jun 23, 2023
@CAM-Gerlach

CAM-Gerlach commented Jun 23, 2023

Copy link
Copy Markdown
Member

@barneygale

image

barneygale and m-aciek reacted with laugh emoji AlexWaygood, ap--, and barneygale reacted with heart emoji
All reactions
  • 😄 2 reactions
  • ❤️ 3 reactions

Sorry, something went wrong.

Uh oh!

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@brettcannon brettcannon brettcannon left review comments
@CAM-Gerlach CAM-Gerlach Awaiting requested review from CAM-Gerlach
@AlexWaygood AlexWaygood Awaiting requested review from AlexWaygood
@merwok merwok Awaiting requested review from merwok

Uh oh!

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

Assignees

No one assigned

Labels

skip news 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.

6 participants

@barneygale @merwok @CAM-Gerlach @brettcannon @AlexWaygood @bedevere-bot
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.