New submission from Larry Hastings <la...@hastings.org>:

There are some functions in the os module that do much the same thing but 
differ only in minor ways, like

* whether or not they follow symbolic links (stat vs lstat)
* taking an extra "dir_fd" parameter (chmod vs fchmodat(3.3))

It would be better if we consolidated these variations into one function which 
took keyword-only parameters that allow access to the alternate functionality.

Here is a sample of the new possible function signatures, as originally 
proposed by Serhiy Storchaka:

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)

My opinion about naming: PEP 8 suggests underscores to separate words in 
non-class identifiers.  So I'd spell those "dir_fd", "src_dir_fd" (etc), 
"remove_dir", and "follow_symlinks".

(While thinking about this, I remembered the infrequently-cited maxim "no 
boolean parameters".  But that's more a guideline than a rule, and it tends to 
be a complaint about how the meaning of the parameter is unclear at a call 
site.  As these will be keyword-only parameters I think their meanings will be 
perfectly clear, so I shan't worry about it.)

----------
messages: 158777
nosy: larry
priority: normal
severity: normal
status: open
title: os module: use keyword-only arguments for dir_fd and nofollow to reduce 
function count

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue14626>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to