<div class="gmail_quote">On Thu, Jun 9, 2011 at 04:05, Victor Stinner <span dir="ltr">&lt;<a href="mailto:victor.stinner@haypocalc.com">victor.stinner@haypocalc.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Le jeudi 09 juin 2011 à 08:16 +0200, Georg Brandl a écrit :<br>
<div><div></div><div class="h5">&gt; On 06/09/11 02:00, brian.curtin wrote:<br>
&gt; &gt; <a href="http://hg.python.org/cpython/rev/88e318166eaf" target="_blank">http://hg.python.org/cpython/rev/88e318166eaf</a><br>
&gt; &gt; changeset:   70713:88e318166eaf<br>
&gt; &gt; branch:      3.2<br>
&gt; &gt; parent:      70700:0aa3064d1cef<br>
&gt; &gt; user:        Brian Curtin &lt;<a href="mailto:brian@python.org">brian@python.org</a>&gt;<br>
&gt; &gt; date:        Wed Jun 08 18:17:18 2011 -0500<br>
&gt; &gt; summary:<br>
&gt; &gt;   Fix #11583. Changed os.path.isdir to use GetFileAttributes instead of os.stat.<br>
&gt; &gt;<br>
&gt; &gt; By changing to the Windows GetFileAttributes API in nt._isdir we can figure<br>
&gt; &gt; out if the path is a directory without opening the file via os.stat. This has<br>
&gt; &gt; the minor benefit of speeding up os.path.isdir by at least 2x for regular<br>
&gt; &gt; files and 10-15x improvements were seen on symbolic links (which opened the<br>
&gt; &gt; file multiple times during os.stat). Since os.path.isdir is used in<br>
&gt; &gt; several places on interpreter startup, we get a minor speedup in startup time.<br>
&gt; &gt;<br>
&gt; &gt; files:<br>
&gt; &gt;   Lib/ntpath.py         |  13 ++++++++++<br>
&gt; &gt;   Misc/NEWS             |   3 ++<br>
&gt; &gt;   Modules/posixmodule.c |  37 +++++++++++++++++++++++++++++++<br>
&gt; &gt;   3 files changed, 53 insertions(+), 0 deletions(-)<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; diff --git a/Lib/ntpath.py b/Lib/ntpath.py<br>
&gt; &gt; --- a/Lib/ntpath.py<br>
&gt; &gt; +++ b/Lib/ntpath.py<br>
&gt; &gt; @@ -672,3 +672,16 @@<br>
&gt; &gt;  def sameopenfile(f1, f2):<br>
&gt; &gt;      &quot;&quot;&quot;Test whether two file objects reference the same file&quot;&quot;&quot;<br>
&gt; &gt;      return _getfileinformation(f1) == _getfileinformation(f2)<br>
&gt; &gt; +<br>
&gt; &gt; +<br>
&gt; &gt; +try:<br>
&gt; &gt; +    # The genericpath.isdir implementation uses os.stat and checks the mode<br>
&gt; &gt; +    # attribute to tell whether or not the path is a directory.<br>
&gt; &gt; +    # This is overkill on Windows - just pass the path to GetFileAttributes<br>
&gt; &gt; +    # and check the attribute from there.<br>
&gt; &gt; +    from nt import _isdir<br>
&gt; &gt; +except ImportError:<br>
&gt; &gt; +    from genericpath import isdir as _isdir<br>
&gt; &gt; +<br>
&gt; &gt; +def isdir(path):<br>
&gt; &gt; +    return _isdir(path)<br>
&gt;<br>
&gt; Not that it matters, but ISTM that this would be faster as<br>
&gt;<br>
&gt; try:<br>
&gt;     from nt import _isdir as isdir<br>
&gt; except ImportError:<br>
&gt;     pass<br>
<br>
</div></div>I would matter if _isdir() had a docstring, but it doesn&#39;t :-)<br>
genericpath.isdir() has the following doc:<br>
<br>
def isdir(s):<br>
    &quot;&quot;&quot;Return true if the pathname refers to an existing directory.&quot;&quot;&quot;</blockquote><div><br></div><div><a href="http://hg.python.org/lookup/d40609dd01e0">http://hg.python.org/lookup/d40609dd01e0</a> adds the docstring back in and redoes the imports as Georg mentioned, which is better.<br>
Thanks for having a look. </div></div>