You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
os module: use keyword-only arguments for dir_fd and nofollow to reduce function count #58831
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/larryhastings'closed_at=<Date2012-06-23.20:41:18.101>created_at=<Date2012-04-19.23:52:38.460>labels= ['type-feature', 'library', 'release-blocker']
title='os module: use keyword-only arguments for dir_fd and nofollow to reduce function count'updated_at=<Date2015-09-21.23:29:45.974>user='https://github.com/larryhastings'
Second pass at my patch. Incorporates suggestions from Serhiy's review--thanks, Serhiy!
Still not ready for checkin. > 80 col lines, no docs, docstrings are messy. But code is ready for (further) review. Code passes regression test suite without errors.
I discovered that fchmodat() doesn't actually support
AT_SYMLINK_NOFOLLOW! glibc documents using the flag, then
comically notes that it doesn't actually work. Specifying
it results in ENOTSUP every time. os.chmod() now accomodates
this; it throws NotImplementedError if it detects this situation.
However it should also Just Work once glibc supports it.
While editing the docstrings, I noticed that several of them
had old-style octal constants ;-) I fixed 'em.
I added support for the remove_dir argument to unlink/remove
on Windows. I also made it work on non-Windows even when
unlinkat() is not available.
BTW: If PEP-362 is accepted, and this patch makes it for 3.3 (both of which I think will happen), I'll hand-code signatures for the functions that may throw NotImplementedError so users can use "is_implemented" to LBYL.
I haven't read the code, but from Larry's description this looks great to me. It's amazing how many extra functions were added to the os module since 3.2! I also agree that the redundant functions that existed in 3.2 should stay and I don't see it's fair to deprecate them. I do hope that not too many people have written code based on the 3.3 alphas using all those extra functions, but I suppose they will get what they paid for.
Everything else Larry wrote also sounds reasonable to me.
Arfrever commented on Jun 9, 2012
Arfrevermannequin
Mannequin
More actions
Previously existing redundant functions could be deprecated in documentation.
Previously existing redundant functions could be
deprecated in documentation.
As in, don't start a "deprecation cycle" (warning in 3.3, deprecated in 3.4, gone in 3.5), just document "consider using this other function instead"? That's probably worth doing. I wouldn't use the word "deprecated" though, I'd just suggest a "see also".
Maybe we could remove the redundant functions in 4.0. I'll put it on my wishlist :)
The big change: I removed the "fd=" parameters. Now, functions that
accept either a path or a file descriptor simply take either as their
"path" argument. I ran it by Guido and he thought it sounded fine,
so I tried it--and I think it's a definite improvement. (Thanks to
Jim Jewett for suggesting it--tbh I'd considered it before, but
looking at it through fresh eyes helped!)
Also new in this patch: you can now LBYL for the fd, dir_fd, and
follow_symlinks parameters. Just check to see if the function is
in os.supports_<name of parameter>. For example:
if os.chown in os.supports_dir_fd:
os.chown(path, dir_fd=whatnot)
The third big bit of news: the patch works under Windows!
I attempted to support Mac OS X 10.3, specifically the weak linking
to statvfs, fstatvfs, and lchown. However I don't have a Mac (much
less one running 10.3) so I can't test this.
I *think* the docstrings are all fixed. The only thing I know that
needs to be done are the docs (and Misc/NEWS).
I really wanna get this in before the feature freeze. I promise to
support it through the betas... can I puh-leez check it in?
And what if the system supports symlink and doesn't support
at-functions, follow_symlinks=False and file is not symlink. Should it
be NotImplementedError?
Traceback (most recent call last):
File "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows7\build\lib\test\test_shutil.py", line 1158, in test_non_matching_modeself.assertIsNone(rv)
AssertionError: 'c:\\users\\db3l\\appdata\\local\\temp\\tmp7n6ojp\\tmp5tt9pa.exe' is not None
Activity
larryhastings commentedon Jun 4, 2012
Second pass at my patch. Incorporates suggestions from Serhiy's review--thanks, Serhiy!
Still not ready for checkin. > 80 col lines, no docs, docstrings are messy. But code is ready for (further) review. Code passes regression test suite without errors.
serhiy-storchaka commentedon Jun 4, 2012
Well, I'm going to ignore the long lines and documentation. The patch is
really big and impressive.
larryhastings commentedon Jun 4, 2012
I'm not sure that "long" and "impressive" are words that go together when describing a patch ;-)
larryhastings commentedon Jun 8, 2012
Here's a nice fresh minor update.
Notes on this third patch:
The docstrings are now done.
I discovered that fchmodat() doesn't actually support
AT_SYMLINK_NOFOLLOW! glibc documents using the flag, then
comically notes that it doesn't actually work. Specifying
it results in ENOTSUP every time. os.chmod() now accomodates
this; it throws NotImplementedError if it detects this situation.
However it should also Just Work once glibc supports it.
While editing the docstrings, I noticed that several of them
had old-style octal constants ;-) I fixed 'em.
I added support for the remove_dir argument to unlink/remove
on Windows. I also made it work on non-Windows even when
unlinkat() is not available.
larryhastings commentedon Jun 8, 2012
BTW: If PEP-362 is accepted, and this patch makes it for 3.3 (both of which I think will happen), I'll hand-code signatures for the functions that may throw NotImplementedError so users can use "is_implemented" to LBYL.
gvanrossum commentedon Jun 9, 2012
I haven't read the code, but from Larry's description this looks great to me. It's amazing how many extra functions were added to the os module since 3.2! I also agree that the redundant functions that existed in 3.2 should stay and I don't see it's fair to deprecate them. I do hope that not too many people have written code based on the 3.3 alphas using all those extra functions, but I suppose they will get what they paid for.
Everything else Larry wrote also sounds reasonable to me.
Arfrever commentedon Jun 9, 2012
Previously existing redundant functions could be deprecated in documentation.
larryhastings commentedon Jun 9, 2012
As in, don't start a "deprecation cycle" (warning in 3.3, deprecated in 3.4, gone in 3.5), just document "consider using this other function instead"? That's probably worth doing. I wouldn't use the word "deprecated" though, I'd just suggest a "see also".
Maybe we could remove the redundant functions in 4.0. I'll put it on my wishlist :)
larryhastings commentedon Jun 21, 2012
New patch! What's new:
The big change: I removed the "fd=" parameters. Now, functions that
accept either a path or a file descriptor simply take either as their
"path" argument. I ran it by Guido and he thought it sounded fine,
so I tried it--and I think it's a definite improvement. (Thanks to
Jim Jewett for suggesting it--tbh I'd considered it before, but
looking at it through fresh eyes helped!)
Also new in this patch: you can now LBYL for the fd, dir_fd, and
follow_symlinks parameters. Just check to see if the function is
in os.supports_<name of parameter>. For example:
if os.chown in os.supports_dir_fd:
os.chown(path, dir_fd=whatnot)
The third big bit of news: the patch works under Windows!
I attempted to support Mac OS X 10.3, specifically the weak linking
to statvfs, fstatvfs, and lchown. However I don't have a Mac (much
less one running 10.3) so I can't test this.
I *think* the docstrings are all fixed. The only thing I know that
needs to be done are the docs (and Misc/NEWS).
I really wanna get this in before the feature freeze. I promise to
support it through the betas... can I puh-leez check it in?
larryhastings commentedon Jun 22, 2012
Fifth iteration of my patch. Everything is done, and I really think it's ready to be checked in.
regression test suite identically to trunk on Windows 32-bit.
serhiy-storchaka commentedon Jun 22, 2012
And what if the system supports symlink and doesn't support
at-functions, follow_symlinks=False and file is not symlink. Should it
be NotImplementedError?
python-dev commentedon Jun 22, 2012
New changeset 27f9c26fdd8b by Larry Hastings in branch 'default':
Issue bpo-14626: Large refactoring of functions / parameters in the os module.
http://hg.python.org/cpython/rev/27f9c26fdd8b
python-dev commentedon Jun 23, 2012
New changeset 04fd8f77a58e by Larry Hastings in branch 'default':
Issue bpo-14626: Fix buildbot issues on FreeBSD (AMD64). (Fingers crossed.)
http://hg.python.org/cpython/rev/04fd8f77a58e
python-dev commentedon Jun 23, 2012
New changeset e1e0eeb07398 by Larry Hastings in branch 'default':
Issue bpo-14626: Fix buildbot issue on x86 Tiger 3.x.
http://hg.python.org/cpython/rev/e1e0eeb07398
python-dev commentedon Jun 23, 2012
New changeset 66f7377547d5 by Larry Hastings in branch 'default':
Issue bpo-14626: Fix buildbot issue on OpenIndiana 3.x machines. (Hopefully.)
http://hg.python.org/cpython/rev/66f7377547d5
pitrou commentedon Jun 23, 2012
27f9c26fdd8b broke test_shutil on the Windows buildbots:
======================================================================
FAIL: test_basic (test.test_shutil.TestWhich)
----------------------------------------------------------------------
======================================================================
FAIL: test_full_path_short_circuit (test.test_shutil.TestWhich)
----------------------------------------------------------------------
======================================================================
FAIL: test_non_matching_mode (test.test_shutil.TestWhich)
----------------------------------------------------------------------
======================================================================
FAIL: test_pathext_checking (test.test_shutil.TestWhich)
----------------------------------------------------------------------
======================================================================
FAIL: test_relative (test.test_shutil.TestWhich)
----------------------------------------------------------------------
pitrou commentedon Jun 23, 2012
The
rmdirargument to unlink() looks completely crazy to me. Instead rmdir() should be called when one wants to rmdir() a fd.birkenfeld commentedon Jun 23, 2012
I agree with Antoine. I've opened bpo-15154 to track this.
birkenfeld commentedon Jun 23, 2012
The Windows buildbots are now content; closing.
python-dev commentedon Sep 21, 2015
New changeset a138a1131bae by Victor Stinner in branch 'default':
Issue bpo-25207, bpo-14626: Fix ICC compiler warnings in posixmodule.c
https://hg.python.org/cpython/rev/a138a1131bae
python-dev commentedon Sep 21, 2015
New changeset 170cd0104267 by Victor Stinner in branch 'default':
Issue bpo-25207, bpo-14626: Fix my commit.
https://hg.python.org/cpython/rev/170cd0104267