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

Make os.Pathlike more similar to a Protocol #126705

Closed
tungol opened this issue Nov 11, 2024 · 0 comments
Closed

Make os.Pathlike more similar to a Protocol #126705

tungol opened this issue Nov 11, 2024 · 0 comments
Labels
topic-typing type-feature A feature request or enhancement

Comments

@tungol
Copy link
Contributor

tungol commented Nov 11, 2024

Feature or enhancement

Proposal:

#83066 considered making os.Pathlike a protocol, but rejected the idea due to not wanting to import typing into os.py.

As an alternative, I propose making more it more protocol-like in two ways:

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

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@tungol tungol added the type-feature A feature request or enhancement label Nov 11, 2024
AlexWaygood pushed a commit that referenced this issue Nov 12, 2024
it can now be used as a base class in other protocols
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-typing type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants