Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2187)

#14626: os module: use keyword-only arguments for dir_fd and nofollow to reduce function count

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 months ago by larry
Modified:
11 months ago
Reviewers:
storchaka, jimjjewett, georg
CC:
gvanrossum, Georg, AntoinePitrou, larry, Benjamin Peterson, Arfrever.FTA_GMail.Com, r.david.murray, Charles-François Natali, Yury.Selivanov, rosslagerwall, devnull_psf.upfronthosting.co.za, storchaka
Visibility:
Public.

Patch Set 1 #

Total comments: 20

Patch Set 2 #

Patch Set 3 #

Total comments: 20

Patch Set 4 #

Patch Set 5 #

Total comments: 62
Unified diffs Side-by-side diffs Delta from patch set Stats Patch
Doc/library/os.rst View 1 2 3 4 41 chunks +488 lines, -433 lines 34 comments Download
Lib/os.py View 1 2 3 4 10 chunks +104 lines, -13 lines 3 comments Download
Lib/shutil.py View 1 2 3 4 2 chunks +35 lines, -26 lines 5 comments Download
Lib/test/support.py View 1 2 3 4 1 chunk +2 lines, -2 lines 0 comments Download
Lib/test/test_os.py View 1 2 3 4 6 chunks +84 lines, -82 lines 8 comments Download
Lib/test/test_posix.py View 1 2 3 4 16 chunks +109 lines, -119 lines 4 comments Download
Lib/test/test_shutil.py View 1 2 3 4 5 chunks +13 lines, -12 lines 2 comments Download
Misc/NEWS View 1 2 3 4 1 chunk +8 lines, -0 lines 2 comments Download
Modules/_io/fileio.c View 1 2 3 4 2 chunks +1 line, -2 lines 2 comments Download
Modules/posixmodule.c View 1 2 3 4 58 chunks +2749 lines, -2523 lines 2 comments Download

Messages

Total messages: 8
storchaka
Wonderful work, Larry! This is not all of the review, the code requires careful consideration. ...
11 months, 3 weeks ago #1
larry
Patch coming right up. http://bugs.python.org/review/14626/diff/5009/Lib/os.py File Lib/os.py (right): http://bugs.python.org/review/14626/diff/5009/Lib/os.py#newcode365 Lib/os.py:365: if st.S_ISDIR(stat(dir_fd=topfd, path=name).st_mode): On 2012/05/30 ...
11 months, 2 weeks ago #2
Jim.Jewett
http://bugs.python.org/review/14626/diff/5114/Lib/shutil.py File Lib/shutil.py (right): http://bugs.python.org/review/14626/diff/5114/Lib/shutil.py#newcode185 Lib/shutil.py:185: os.setxattr(dst, attr, os.getxattr(src, attr, follow_symlinks=symlinks), follow_symlinks=symlinks) I kept reading ...
11 months, 1 week ago #3
larry
Thanks for the feedback, Jim! The changes discussed below will be in my next diff, ...
11 months ago #4
Georg
Hi Larry, most comments are minor, and don't need to be addressed before feature-freeze. But ...
11 months ago #5
larry
http://bugs.python.org/review/14626/diff/5182/Doc/library/os.rst File Doc/library/os.rst (right): http://bugs.python.org/review/14626/diff/5182/Doc/library/os.rst#newcode636 Doc/library/os.rst:636: These parameters are used as flags to the \*at ...
11 months ago #6
larry
Replying to Serihy's comment which got lost in the mix somehow. http://bugs.python.org/review/14626/diff/5182/Doc/library/os.rst File Doc/library/os.rst (right): ...
11 months ago #7
Georg
11 months ago #8
http://bugs.python.org/review/14626/diff/5182/Doc/library/os.rst
File Doc/library/os.rst (right):

http://bugs.python.org/review/14626/diff/5182/Doc/library/os.rst#newcode695
Doc/library/os.rst:695: Equivalent to ``os.chmod(fd, mode)``.
On 2012/06/23 00:27:56, larry wrote:
> On 2012/06/22 20:26:02, Georg wrote:
> > Since it existed, or just as of the patch?  In the
> > latter case, that must be noted.  Ditto for a few more
> > instances below.
> 
> Just as part of the patch.
> 
> Happy to note it as you suggest, but not sure what
> specifically you have in mind.  Can you give me an example
> of how I should note this?  "versionadded" seems inaccurate.

"From Python 3.3, equivalent to ..."  But I favor the deprecation.

> > Hmm, thinking about it more, IMO the f* functions should
> > be deprecated (in docs only) right away.
> 
> Deprecated how?  If I just say "deprecated" people will think they might start
> throwing exceptions.  I doubt we will get rid of fchmod--at least, until
Python
> 4.

No, that's not how our deprecations work.  Deprecated APIs can, and at some
point should, only emit DeprecationWarnings, not raise exceptions.  You could
even explicitly say they won't be removed before 4.0 using the
"deprecated-removed" directive.

http://bugs.python.org/review/14626/diff/5182/Doc/library/os.rst#newcode835
Doc/library/os.rst:835: directory, and *path* should be relative; path will then
be relative to
On 2012/06/23 00:27:56, larry wrote:
> On 2012/06/22 20:26:02, Georg wrote:
> > What happens if path is absolute?
> 
> According to the POSIX 1003.1-2008 page on openat(), if path is absolute,
dir_fd
> is ignored.  This is the consistent behavior for all *at() functions in POSIX.

> They is also the behavior for all the additional non-POSIX *at() functions
> defined in glibc (e.g. fchownat, mkfifoat).
> 
> This leads one to theorize: should we detect this situation and instead throw
an
> exception, chiding the user for mixing up their P's and Q's?  My knee-jerk
> reaction: no, let's not make Python overly pedantic.  The POSIX semantics are
> good enough for me.

Agreed.

> > Also, the second "path" should be "the effective path"
> > or something.
> 
> No, I genuinely just meant "path" there.  But I guess that's not clear.
> 
> However, the "effective path" is, the cumulative result of all transformations
> to the path, and is therefore absolute by definition.
> 
> You know what I mean to say here; I'd be interested in an alternate
suggestion.

Right.  Your version is correct with path marked up as *path*.

http://bugs.python.org/review/14626/diff/5182/Doc/library/os.rst#newcode1210
Doc/library/os.rst:1210: using it will raise a :exc:`NotImplementedError`.
On 2012/06/23 00:39:23, larry wrote:
> Serhiy Storchaka had an additional comment here, which Rietveld can't find for
> some reason:
> > 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?
> 
> I see what you mean--if the file is not a symlink, then follow_symlinks should
> be irrelevant.  But the NotImplementedError indicates whether or not the
> functionality is available.
> 
> It's equivalent to saying "if I call lchown() on a file which isn't a symbolic
> link, but lchown isn't supported, can't it just call chown for me?"  If lchown
> isn't available, the program won't link / won't run.  If lchown is available,
> but is a non-working stub (as it is on my Linux box), the function returns an
> error rather than calling chown on my behalf.
> 
> It's plausible that Python could be nicer than C here and fall back when
> possible.  Right now I'm just trying to get the patch in at all; if I succeed
in
> that, I'll come back to this.

For now I agree, let "explicit is better than implicit" prevail.

http://bugs.python.org/review/14626/diff/5182/Doc/library/os.rst#newcode2095
Doc/library/os.rst:2095: A queryable collection of functions, reflecting which
functions in the
On 2012/06/23 00:27:56, larry wrote:
> On 2012/06/22 20:26:02, Georg wrote:
> > "queryable collection" is not a common term.
> > Is it a list, a set, ...?
> 
> It's a set.  But I was trying to leave it ambiguous.  What I was looking for
> here was saying "an object you can use the 'in' operator on."  It's not a map,
> and though it is a iterable that's a poor description.
> 
> I've changed
> "A queriable collection of functions, reflecting" 
> to
> "An object implementing collections.Set indicating"
> Do you have another wording you'd prefer?
> 
> (p.s. I considered making it a callable, but I think a set is just nicer.  And
> probably faster, if you care about such microbenchmarks.)

You could always say a "set-like object", or just "collection" since the "use
the in operator" part is made quite explicit below.

http://bugs.python.org/review/14626/diff/5182/Doc/library/os.rst#newcode2109
Doc/library/os.rst:2109: Currently *dir_fd* parameters only work on UNIX and
UNIX-like platforms;
On 2012/06/23 00:27:56, larry wrote:
> On 2012/06/22 20:26:02, Georg wrote:
> > I think we spell it "Unix".
> 
> Fun trivia: there is a UNIX certification process.  According to the trademark
> holders, only systems that have been thus certified can be called UNIX.  Mac
OS
> X has been certified; Linux never has.  Therefore Linux cannot be rightly
called
> UNIX, but only UNIX-like.
> 
> But I have dropped the phrase "and UNIX-like" as you request.

Ah, I wasn't even talking about that, just the casing.  But dropping the
"Unix-like" is also good for consistency.

http://bugs.python.org/review/14626/diff/5182/Lib/os.py
File Lib/os.py (right):

http://bugs.python.org/review/14626/diff/5182/Lib/os.py#newcode189
Lib/os.py:189: if ((sys.platform != "linux") or
On 2012/06/23 00:27:56, larry wrote:
> On 2012/06/22 20:26:02, Georg wrote:
> > Is "or" correct here?  I understand the comment above such that the function
> > exists (so "HAVE_LCHMOD" exists?), so that "and" would be correct.
> 
> "or" is correct here.  Sorry it's unclear--I guess my comment isn't helping.
> 
> This paragraph is enumerating the os.* functions whose "follow_symlinks"
> parameter actually works.  For os.chmod, there are two functions in glibc on
> Linux that could possibly enable this functionality: lchmod() and fchmodat().
> 
> lchmod() doesn't *actually* work.  It's defined, but when you call it it
returns
> ENOSUP.  Every. Time.  ./configure correctly detects this and concludes
"lchmod
> doesn't work".  So HAVE_LCHMOD is actually *not* defined on Linux.

OK, that was the unclear bit.

http://bugs.python.org/review/14626/diff/5182/Lib/test/test_os.py
File Lib/test/test_os.py (right):

http://bugs.python.org/review/14626/diff/5182/Lib/test/test_os.py#newcode372
Lib/test/test_os.py:372: with self.assertRaises(ValueError):
On 2012/06/23 00:27:56, larry wrote:
> On 2012/06/22 20:26:02, Georg wrote:
> > Why does the exception class change here?
> 
> I don't understand the question.
> 
> This tests passing in *both* "times" and "ns", which is an error.  IIRC which
> exception it should raise was discussed in Rietveld feedback for the utime
issue
> (#14127).  I think ValueError is the right choice.
> 
> Does that answer your question?

Yes.  It seems an unrelated change for this patch; therefore I flagged it.

http://bugs.python.org/review/14626/diff/5182/Lib/test/test_os.py#newcode1845
Lib/test/test_os.py:1845: kernel_version = platform.release()
On 2012/06/23 00:27:56, larry wrote:
> On 2012/06/22 20:26:02, Georg wrote:
> > Uh, that might match version 2.6.x of some unrelated Unix, right?
> 
> I suppose.  But the *xattr functions are most definitely Linux-only.  If you
> like I'll throw a platform == linux check in.

Cannot hurt, for self-documenting purposes.
Sign in to reply to this message.

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7