-
Notifications
You must be signed in to change notification settings - Fork 234
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
Add PathLike to typing #402
Comments
FYI, PEP 519 explicitly rejects adding I've also been thinking about this recently. In addition to PathLike, it would be nice to have a generic alias like |
There's already https://docs.python.org/3/library/os.html#os.PathLike so it's part way there already. And if/when protocols come into Python then there will be a discussion as to whether we should back-fill the stdlib with protocols and I suspect PathLike would be one of them. |
Hm, `os.PathLike` just landed in typeshed (see
python/typeshed#991 and
python/typeshed@41561f1
).
What else is there to do?
…On Tue, Mar 21, 2017 at 10:16 AM, Brett Cannon ***@***.***> wrote:
There's already https://docs.python.org/3/library/os.html#os.PathLike so
it's part way there already.
And if/when protocols come into Python then there will be a discussion as
to whether we should back-fill the stdlib with protocols and I suspect
PathLike would be one of them.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#402 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACwrMroR5zdukbTuOognCdn57wt5nuLzks5roAX4gaJpZM4MjLiM>
.
--
--Guido van Rossum (python.org/~guido)
|
Two things:
|
Hm... So for a I think I know a fix and I'll send it to you. |
It seems |
So, what is the correct way to do it now? |
os.PathLike[str] or os.PathLike[bytes] as described in the original proposal |
While thinking about protocols, it came to my mind that we could add
PathLike
to typing, also we could make it a (runtime) protocol class. As I understand PEP 519, it could be typed like this:So that there will be three allowed types:
PathLike[str]
,PathLike[bytes]
, andPathLike[Union[str, bytes]]
. Or we actually don't needPathLike[Union[str, bytes]]
? In this case we could just useAnyStr
instead ofS
.CC @brettcannon
The text was updated successfully, but these errors were encountered: