Uh oh!
There was an error while loading. Please reload this page.
Add a _typeshed.pyi file and a PathLike alias - #4161
Conversation
This PR only replaces a few potential places where this alias could be used. Closes: python#4131
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Fix whitespace at end of line Add _typeshed to stubtest whitelist
| 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.
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.
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.
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.
I added BytesPath for consistency.
CraftSpider
commented
Jun 3, 2020
For future improvements, what might be considered for |
JelleZijlstra
commented
Jun 3, 2020
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 |
srittau
commented
Jun 3, 2020
Sounds fine to me.
+1, although this can be done in a separate PR.
Agreed.
Good call. I will make it into a package. |
hauntsaninja
left a comment
There was a problem hiding this comment.
Looks good! I also have no good suggestions for AnyPath :-)
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
sproshev
commented
Jun 3, 2020
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