Combining stat/lstat/fstatat etc.
In Python3 added a large number of "at"-functions from the latter Posix standard. Such a large number of names only litters namespace. In C it is necessary for historical reasons (note that fstatat combines the stat and lstat and includes the possibility of extension) and because of static typing. But in Python because of dynamic typing we can extend existing functions. So instead of stat, lstat, and fstatat could use the same function `stat(path, *, dirfd=None, followlinks=True)`. Then `lstat(path)` == `stat(path, followlinks=False)`, and `fstatat(dirfd, path, flags)` == `stat(path, dirfd=(AT_FDCWD if dirfd is None else AT_FDCWD), followlinks=not (flags & AT_SYMLINK_NOFOLLOW))`. As special value for dirfd I suggest using the None, not AT_FDCWD (it's more pythonish). fstat could be included too, by specifically treating the case where the path is integer. And same for other functions. Old lstat and lchown will remain for compatibility as light wrappers around the stat, with time they may become deprecated.
Guido steered me towards this suggestion. I think it's a fine idea. I'm in the process of adding keyword-only arguments to C extension argument parsing (issue #14328), and after that adding a new ns= parameter to os.utime (issue #14127). After that I may take a stab at this, unless you would prefer to be the implementor. Could you please create an issue on the bug tracker to discuss/track this? I'm happy to create the issue if you prefer. //arry/ On 03/10/2012 09:33 AM, Serhiy Storchaka wrote:
In Python3 added a large number of "at"-functions from the latter Posix standard. Such a large number of names only litters namespace. In C it is necessary for historical reasons (note that fstatat combines the stat and lstat and includes the possibility of extension) and because of static typing. But in Python because of dynamic typing we can extend existing functions.
So instead of stat, lstat, and fstatat could use the same function `stat(path, *, dirfd=None, followlinks=True)`. Then `lstat(path)` == `stat(path, followlinks=False)`, and `fstatat(dirfd, path, flags)` == `stat(path, dirfd=(AT_FDCWD if dirfd is None else AT_FDCWD), followlinks=not (flags& AT_SYMLINK_NOFOLLOW))`. As special value for dirfd I suggest using the None, not AT_FDCWD (it's more pythonish). fstat could be included too, by specifically treating the case where the path is integer.
And same for other functions.
Old lstat and lchown will remain for compatibility as light wrappers around the stat, with time they may become deprecated.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
16.03.12 02:48, Larry Hastings написав(ла):
Guido steered me towards this suggestion. I think it's a fine idea. I'm in the process of adding keyword-only arguments to C extension argument parsing (issue #14328), and after that adding a new ns= parameter to os.utime (issue #14127). After that I may take a stab at this, unless you would prefer to be the implementor.
Could you please create an issue on the bug tracker to discuss/track this? I'm happy to create the issue if you prefer.
With my bad English will be better if you create the issue. I will try to prepare a patch (it will be a big patch), when the syntax of the functions will become quite clear. Initially, I assumed the following signatures: access(path, mode, *, followlinks=True, dirfd=None, eaccess=False) chmod(path, mode, *, followlinks=True, dirfd=None) chown(path, uid, gid, *, followlinks=True, dirfd=None) link(srcpath, dstpath, *, followlinks=True, srcdirfd=None, dstdirfd=None) mkdir(path, mode=0o777, *, dirfd=None) mknod(path, mode=0o600, device=0, *, dirfd=None) open(path, flag, mode=0o777, *, dirfd=None) readlink(path, *, dirfd=None) rename(oldpath, newpath, *, olddirfd=None, newdirfd=None) stat(path, *, followlinks=True, dirfd=None) symlink(src, dst, *, dirfd=None) unlink(path, *, removedir=False, dirfd=None) utimes(path[, (atime, mtime)], *, ns=False, dirfd=None) mkfifoat(path, mode=0o666, *, followlinks=True, dirfd=None) But there is a nuisance with several dirfd in link and rename. The problem with naming parameters. Perhaps it would be better instead of using keyword parameter dirfd to pass tuple (dirfd, relpath) as path parameters? The second question is how the user code will check the availability of dirfd functionality. Special global flags in os or sys?
participants (2)
-
Larry Hastings
-
Serhiy Storchaka