-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add a _typeshed.pyi file and a PathLike alias #4161
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
Conversation
This PR only replaces a few potential places where this alias could be used. Closes: python#4131
Fix whitespace at end of line Add _typeshed to stubtest whitelist
stdlib/2and3/_typeshed.pyi
Outdated
|
||
# StrPath and AnyPath can be used in places where a | ||
# path can be used instead of a string, starting with Python 3.6. | ||
if sys.version_info >= (3, 6): | ||
from os import PathLike | ||
StrPath = Union[str, PathLike[str]] | ||
AnyPath = Union[str, bytes, PathLike[AnyStr]] | ||
AnyPath = Union[str, bytes, PathLike[str], PathLike[bytes]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name AnyPath
is mildly confusing because AnyStr
is a typevar and this similarly named alias isn't. Not sure what to call it instead though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, Any
is not a typevar either. We could go with just Path
, but that is confusing with pathlib.Path
. Maybe EitherPath
, but I don't find that particularly clear. (I'm not suggesting WhateverPath
, although it's kind of fitting. :) )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know at least the path modules (ntpath, posixpath, os.path, etc) also defines a BytesPath, is that worth moving here now, and updating those files?
For naming, I'm personally okay with AnyPath
, as I can't come up with a clearer name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added BytesPath
for consistency.
For future improvements, what might be considered for |
For Other things we could add here are common protocols, like SupportsLessThan from #4155 Not sure about typevars, at least for simple ones—they're usually pretty easy to define, and because using typevars is tricky, it's good to have them close to the definition sites. Also, should |
Sounds fine to me.
+1, although this can be done in a separate PR.
Agreed.
Good call. I will make it into a package. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I also have no good suggestions for AnyPath :-)
I'd suggest to move open function modes from |
This PR only replaces a few potential places where this alias could be
used.
Closes: #4131