<p>+1! Thanks for pushing this.</p>
<div class="gmail_quote">On Apr 15, 2012 4:04 AM, &quot;Brett Cannon&quot; &lt;<a href="mailto:brett@python.org">brett@python.org</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>To start off, what I am about to propose was brought up at the PyCon language summit and the whole room agreed with what I want to do here, so I honestly don&#39;t expect much of an argument (famous last words).</div>


<div><br></div>In the &quot;ancient&quot; import.c days, a lot of import&#39;s stuff was hidden deep in the C code and in no way exposed to the user. But with importlib finishing PEP 302&#39;s phase 2 plans of getting imoprt to be properly refactored to use importers, path hooks, etc., this need no longer be the case.<div>


<br></div><div>So what I propose to do is stop having import have any kind of implicit machinery. This means sys.meta_path gets a path finder that does the heavy lifting for import and sys.path_hooks gets a hook which provides a default finder. As of right now those two pieces of machinery are entirely implicit in importlib and can&#39;t be modified, stopped, etc.</div>


<div><br></div><div>If this happens, what changes? First, more of importlib will get publicly exposed (e.g. the meta path finder would become public instead of private like it is along with everything else that is publicly exposed). Second, import itself technically becomes much simpler since it really then is about resolving module names, traversing sys.meta_path, and then handling fromlist w/ everything else coming from how the path finder and path hook work.</div>


<div><br></div><div>What also changes is that sys.meta_path and sys.path_hooks cannot be blindly reset w/o blowing out import. I doubt anyone is even touching those attributes in the common case, and the few that do can easily just stop wiping out those two lists. If people really care we can do a warning in 3.3 if they are found to be empty and then fall back to old semantics, but I honestly don&#39;t see this being an issue as backwards-compatibility would just require being more careful of what you delete (which I have been warning people to do for years now) which is a minor code change which falls in line with what goes along with any new Python version.</div>


<div><br></div><div>And lastly, sticking None in sys.path_importer_cache would no longer mean &quot;do the implicit thing&quot; and instead would mean the same as NullImporter does now (which also means import can put None into sys.path_importer_cache instead of NullImporter): no finder is available for an entry on sys.path when None is found. Once again, I don&#39;t see anyone explicitly sticking None into sys.path_importer_cache, and if they are they can easily stick what will be the newly exposed finder in there instead. The more common case would be people wiping out all entries of NullImporter so as to have a new sys.path_hook entry take effect. That code would instead need to clear out None on top of NullImporter as well (in Python 3.2 and earlier this would just be a performance loss, not a semantic change). So this too could change in Python 3.3 as long as people update their code like they do with any other new version of Python.</div>


<div><br></div><div>In summary, I want no more magic &quot;behind the curtain&quot; for Python 3.3 and import: sys.meta_path and sys.path_hooks contain what they should and if they are emptied then imports will fail and None in sys.path_importer_cache means &quot;no finder&quot; instead of &quot;use magical, implicit stuff&quot;.</div>


<br>_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-dev" target="_blank">http://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="http://mail.python.org/mailman/options/python-dev/anacrolix%40gmail.com" target="_blank">http://mail.python.org/mailman/options/python-dev/anacrolix%40gmail.com</a><br>
<br></blockquote></div>