Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-89812: Addpathlib._PurePathExt#104810

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

barneygale
Copy link
Contributor

@barneygalebarneygale commentedMay 23, 2023
edited
Loading

Move__fspath__(),__bytes__() andas_uri() methods fromPurePath to a new_PurePathExt subclass. This new subclass is inherited byPurePosixPath,PureWindowsPath andPath.

BecausePurePath isn't directly instantiatable (you get aPurePosixPath orPureWindowsPath instance back), this shouldn't change user-facing behaviour.

The methods must not be inherited futuretarfile.TarPath andpathlib.AbstractPath classes, which will subclassPurePath.

This internal class excludes the `__fspath__()`, `__bytes__()` and`as_uri()` methods, which must not be inherited by a future`tarfile.TarPath` class.
@barneygalebarneygale changed the titleGH-89812: Addpathlib._LexicalPathGH-89812: Addpathlib._BasePurePathMay 23, 2023
@barneygale
Copy link
ContributorAuthor

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

barneygaleand others added2 commitsMay 24, 2023 16:04
barneygaleand others added2 commitsMay 24, 2023 17:36
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@barneygale
Copy link
ContributorAuthor

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

@barneygalebarneygale marked this pull request as draftJune 7, 2023 20:26
@barneygalebarneygale marked this pull request as ready for reviewJune 14, 2023 16:12
@barneygale
Copy link
ContributorAuthor

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

@barneygalebarneygale changed the titleGH-89812: Addpathlib._BasePurePathGH-89812: Addpathlib._PurePathExtJun 22, 2023
@barneygale
Copy link
ContributorAuthor

barneygale commentedJun 22, 2023
edited
Loading

I've revised the implementation such that the methods are actually removed fromPurePath. This will allow our futureAbstractPath class to inheritPurePath, as it should conceptually:

image

(Contrast this with theearlier proposed hierarchy wherePurePath andAbstractPath are siblings.

The methods are moved to a new_PurePathExt class, which is inherited byPurePosixPath,PureWindowsPath andPath.

This changewill not be visible to users who try to instantiatePurePath, because they'll always get aPurePosixPath orPureWindowsPath instance back.

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

@barneygale
Copy link
ContributorAuthor

barneygale commentedJun 22, 2023
edited
Loading

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

@merwok
Copy link
Member

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

@barneygale
Copy link
ContributorAuthor

barneygale commentedJun 23, 2023
edited
Loading

Oh I totally agree. I'd prefer to addonlypathlib.AbstractPath, but I'm prevented by the fact thatPurePath 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 thePurePath initialiser instead. Oh well...

@barneygalebarneygale marked this pull request as draftJune 23, 2023 11:57
@barneygale
Copy link
ContributorAuthor

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

@barneygale
Copy link
ContributorAuthor

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

CAM-Gerlach reacted with laugh emoji

@CAM-Gerlach
Copy link
Member

@barneygale

image

barneygale and m-aciek reacted with laugh emojiAlexWaygood, ap--, and barneygale reacted with heart emoji

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

@brettcannonbrettcannonbrettcannon left review comments

@CAM-GerlachCAM-GerlachAwaiting requested review from CAM-Gerlach

@AlexWaygoodAlexWaygoodAwaiting requested review from AlexWaygood

@merwokmerwokAwaiting requested review from merwok

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@barneygale@merwok@CAM-Gerlach@brettcannon@AlexWaygood@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp