<br><br><div class="gmail_quote">On Sun, Feb 28, 2010 at 12:46, Nick Coghlan <span dir="ltr"><<a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">Brett Cannon wrote:<br>
> Actually it's four: name/__init__.py, name/__init__.pyc, name.py, and<br>
> then name.pyc. And just so people have terminology to go with all of<br>
> this, this search is what the finder does to say whether it can or<br>
> cannot handle the requested module.<br>
<br>
</div>Huh, I thought we checked for the directory first and only then checked<br>
for the __init__ module within it (hence the generation of ImportWarning<br>
when we don't find __init__ after finding a correctly named directory).<br>
So a normal miss (i.e. no directory) only needs one stat call.<br>
<br>
(However, I'll grant that I haven't looked at this particular chunk of<br>
code in a fairly long time, so I could easily be wrong).<br>
<br>
Robert raises a good point about the checks for extension modules as<br>
well - we should get an accurate count here so Barry's PEP can pitch the<br>
proportional reduction in stat calls accurately.<br></blockquote><div><br></div><div>Here are the details (from Python/import.c:find_module) assuming that everything has failed to the point of trying for the implicit sys.path importers:</div>
<div><br></div><div>stat_info = stat(name)</div><div>if stat_info.exists and stat_info.is_dir:</div><div> if stat(name/__init__.py) || stat(name/__init__.pyc):</div><div> load(name)</div><div>else:</div><div> for ext in ('.so', 'module.so', '.py', 'pyc'): # Windows has an extra check for .pyw files.</div>
<div> if open(name + ext):</div><div> load(name)</div><div><br></div><div>So there are a total of five to six depending on the OS (actually, VMS goes up to eight!) before a search path is considered not to contain a module.</div>
<div><br></div><div>And thanks to doing this I realized importlib is not stat'ing the directory first which should fail faster than checking for the __init__ files every time.</div><div><br></div><div>-Brett</div><div>
<br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5"><br>
Cheers,<br>
Nick.<br>
<br>
--<br>
Nick Coghlan | <a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a> | Brisbane, Australia<br>
---------------------------------------------------------------<br>
</div></div></blockquote></div><br>