-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Some os and os.path function signatures do not admit legal integer (file descriptor) arguments #1653
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
#1645 is fixing a number of these. Can you check for this again after that PR is merged? |
I just read through the #1645 patch and it looks like the following still need to be addressed: os.listdir, os.path.exist. |
Fix python#1653 Use `_FdOrPathType` when possible in `os.path` module.
Fix python#1653 Use `_FdOrPathType` when possible in `os.path` module.
From a typing correctness POV it's really a shame that these functions were made polymorphic. The use cases for FDs here are very esoteric and it means that some buggy code will now no longer be caught by mypy. I definitely don't endorse doing this to anything in os.path -- that's a coincidence and may break at any time. Also, this should not typecheck when platform isn't one of the UNIXoid systems. (OK, let's say it should not typecheck on Windows. :-) |
@gvanrossum I'm sorry but I don't follow. |
Sorry I did not realize that it was documented. And it seems to be cross-platform too. |
To be clear, |
|
From the docs:
Not sure if we want to widen the types for all platforms, or try to special case just for Posix. Here is a list of offenders (via
suports_fd
on python3.7): chdir, chmod, chown, listdir, pathconf, scandir, stat, statvfs, truncate, utime.I also looked through os.path manually, and found one more: os.path.exists.
os.chdir(path)
typeshed:
def chdir(path: _PathType) -> None: ...
os.chmod(path, mode, *, dir_fd=None, follow_symlinks=True)
typeshed:
def chmod(path: _PathType, mode: int) -> None: ...
os.chown(path, uid, gid, *, dir_fd=None, follow_symlinks=True)
typeshed:
def chown(path: _PathType, uid: int, gid: int) -> None: ... # Unix only
os.listdir(path=’.’)
typeshed:
os.pathconf(path, name)
typeshed:
def pathconf(path: _PathType, name: Union[str, int]) -> int: ... # Unix only
os.stat(path, *, dir_fd=None, follow_symlinks=True)
typeshed:
def stat(path: _PathType) -> stat_result: ...
os.statvfs(path)
typeshed:
def statvfs(path: _PathType) -> statvfs_result: ... # Unix only
os.truncate(path, length)
typeshed:
def truncate(path: Union[_PathType, int], length: int) -> None: ... # Unix only up to version 3.4
os.utime(path, times=None, *, [ns, ]dir_fd=None, follow_symlinks=True)
typeshed:
def utime(path: _PathType, times: Optional[Union[Tuple[int, int], Tuple[float, float]]] = ...,
os.path.exists(path)
typeshed:
def exists(path: _PathType) -> bool: ...
The text was updated successfully, but these errors were encountered: