Allow os.readlink to accept path-like objects#1441
Allow os.readlink to accept path-like objects#1441JelleZijlstra merged 2 commits intopython:masterfrom
os.readlink to accept path-like objects#1441Conversation
stdlib/3/os/__init__.pyi
Outdated
| 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.
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())) # ErrorThis 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.