-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
State of os.path and path types #1841
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
Comments
Yes, this is still a goal and I'm glad that you're looking into this.
Thanks!
|
All right. I don't think I have the capacity currently to merge the To formulate that into a question: Should I replace signatures in the form |
Maybe you could do something like what was done for if sys.version_info >= (3, 6):
def readlink(path: Union[AnyStr, PathLike[AnyStr]], *, dir_fd: Optional[int] = ...) -> AnyStr: ... |
Isn't that exactly what triggers python/mypy#3644? Or would that only apply to |
That's an interesting option. I'm too tired tonight to consider it, sorry. Maybe @JukkaL has an opinion. At the very least you should check everything that currently uses |
One option is to use an overloaded function, which mypy seems to handle already: @overload
def readlink(path: AnyStr, *, dir_fd: Optional[int] = 0) -> AnyStr: ...
@overload
def readlink(path: PathLike[AnyStr], *, dir_fd: Optional[int] = 0) -> AnyStr: ... Or we could prioritize fixing python/mypy#3644 -- it doesn't feel to me like it would be a tricky one, but I could be mistaken. |
For starters, I tried replacing all current usages of if sys.version_info >= (3, 6):
from builtins import _PathLike
_PathType = Union[bytes, Text, _PathLike]
_GenPathType = Union[AnyStr, _PathLike[AnyStr]]
else:
_PathType = Union[bytes, Text]
_GenPathType = AnyStr However, running
|
Looks like you can't have an alias for a type variable (like Another option to look into might be to define |
Do the export where? |
Oh, I think I meant PathLike, in os/__init__.pyi.
|
The parts about PathType are covered in the more focused #1997, and the question about merging has been answered, so closing this issue. |
According to a few older PRs (#1150, #1459), it seems like the stubs for for
2
and3
should be merged into a2and3
version, however some commits continue to introduce changes to only one of theos
files (notably #1645). Merging them is supposedly blocked onos/__init__.py
.Is this merge still a goal moving forward? If not, I suppose they would benefit from some simplification (notably the 2 version).
Furthermore, I intend to add a couple more
_PathType
type signatures toos.path
functions as pretty much all of them support it internally, but only ~half of them are annotated correctly. Ideally,Union[AnyStr, _PathLike[AnyStr]]
is to be used for the_PathType
type (via #1441), but it seems like that is still blocked on python/mypy#3644. When replacingAnyStr
with_PathType
(with_PathLike
instead of_PathLike[AnyStr]
), the generic properties of the functions signatures are lost, so that would be a regression, but the annotations are currently in a mixed state anyway.The text was updated successfully, but these errors were encountered: