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-126705: Make os.PathLike more like a protocol#126706

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

Merged
AlexWaygood merged 3 commits intopython:mainfromtungol:pathlike
Nov 12, 2024

Conversation

@tungol
Copy link
Contributor

@tungoltungol commentedNov 11, 2024
edited by bedevere-appbot
Loading

This MR makesos.PathLike more protocol-like in two ways:

  1. adds it to typing._PROTO_ALLOWLIST so it can be used as a base class in other protocols
  2. useclass PathLike(metaclass=abc.ABCMeta) instead ofclass PathLike(abc.ABC). This aligns with the other protocol-like ABCs incollections.abc. Actual protocols do have that metaclass but don't have theabc.ABC base class. Doing this makes it a little smoother for typeshed to define the class asclass PathLike(Protocol) in the stubs.

Copy link
Contributor

@bswckbswck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

On-topic: LGTM
Off-topic:
Makes me wonder why not allowABC in bases here:

basein {object,Generic}

It's such a common base class, is there anything mutually exclusive with abstract classes and protocols? This PR proves false.

@tungol
Copy link
ContributorAuthor

I think the need for the explicit allowlist is that not all ABCs are protocol-like; only ABCs with a__subclass_hook__ that's properly constructed for that purpose should be mixed with protocols. It's not that they're mutually exclusive, it's just that most of them aren't suitable.

AlexWaygood reacted with thumbs up emoji

@tungol
Copy link
ContributorAuthor

I think I see the confusion: being able to use PathLike as a protocol base only requires adding it to_PROTO_ALLOWLIST. Adjusting the inheritance of the class is not required for that functionality, it just makes it a little cleaner. Of my two points, number 1 can be implemented without number 2 (or vice versa).

AlexWaygood reacted with thumbs up emoji

Copy link
Contributor

@asvetlovasvetlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks good, thanks!

@AlexWaygoodAlexWaygoodenabled auto-merge (squash)November 12, 2024 17:46
@AlexWaygoodAlexWaygood merged commita83472f intopython:mainNov 12, 2024
40 checks passed
@tungoltungol deleted the pathlike branchNovember 12, 2024 18:02
picnixz pushed a commit to picnixz/cpython that referenced this pull requestDec 8, 2024
it can now be used as a base class in other protocols
ebonnal pushed a commit to ebonnal/cpython that referenced this pull requestJan 12, 2025
it can now be used as a base class in other protocols
@bswckbswck mentioned this pull requestJan 27, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@sobolevnsobolevnsobolevn left review comments

@asvetlovasvetlovasvetlov approved these changes

@AlexWaygoodAlexWaygoodAlexWaygood approved these changes

@JelleZijlstraJelleZijlstraAwaiting requested review from JelleZijlstraJelleZijlstra is a code owner

+1 more reviewer

@bswckbswckbswck approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@tungol@asvetlov@sobolevn@bswck@AlexWaygood

[8]ページ先頭

©2009-2025 Movatter.jp