-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Allow os.readlink
to accept path-like objects
#1441
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
stdlib/3/os/__init__.pyi
Outdated
@@ -319,7 +319,7 @@ def mkdir(path: _PathType, mode: int = ...) -> None: ... | |||
def makedirs(path: _PathType, mode: int = ..., | |||
exist_ok: bool = ...) -> None: ... | |||
def pathconf(path: _PathType, name: Union[str, int]) -> int: ... # Unix only | |||
def readlink(path: AnyStr) -> AnyStr: ... | |||
def readlink(path: _PathType) -> AnyStr: ... |
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.
This is a little subtle, but _PathType
is actually generic over AnyStr
. And you'll need that for the return type. You can try to fix this by adding _PathType[AnyStr]
. Hopefully that fixes the issue (which is actually caused by the inferred return type of readlink()
being broken by to this change).
I've got an example where I don't know what it should do. import os
class P(os.PathLike[bytes]):
def __fspath__(self) -> bytes:
return b'x'
print(os.readlink(P())) # Error This produces
Without this PR it gives a different error:
(At runtime it fails because the stdlib's I'm not sure whether this is worth holding up this PR for though, since it's not truly a regression (more of a detour maybe :-). |
That seems like a mypy bug, since |
Maybe, I don't have time to look into it right now. :-( |
Reported Guido's example above as a mypy bug in python/mypy#3644. @rhysparry thanks for your contribution! |
* python/master: Added stub for toaiff module (python#1455) Added stub for user module (python#1454) Add more multiprocessing function stubs (python#1435) PyYaml: uncomment commented out imports and add missing classmethod decorators (python#1439) Allow `os.readlink` to accept path-like objects (python#1441) Support named attributes in `os.uname()` result (python#1445) Fix signature for slite3.fetchmany (python#1444) Add __name__ field to MethodType (python#1442) Add TypedDict total argument (python#1443)
No description provided.