[Python-ideas] Combining stat/lstat/fstatat etc.
larry at hastings.org
Fri Mar 16 01:48:24 CET 2012
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.
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 at python.org
More information about the Python-ideas