[Python-Dev] PEP 420 - dynamic path computation is missing rationale (original) (raw)

Eric V. Smith eric at trueblade.com
Thu May 24 02:24:01 CEST 2012


Here's another suggestion: instead of modifying the finder/loader code to pass these names through, assume that we can always find (modulename, attributename) with this code:

def findparentpathnames(module): parent, dot, me = module.name.rpartition('.') if dot == '': return 'sys', 'path' return parent, 'path'

import glob findparentpathnames(glob) ('sys', 'path') import unittest.test.testcase findparentpathnames(unittest.test.testcase) ('unittest.test', 'path') I guess it's a little more fragile than passing in these names to NamespaceLoader, but it requires less code to change. I think I'll whip this up in the pep-420 branch.

I tried this approach and it works fine. The only caveat is that it assumes that the parent path can always be computed as described above, independent of what's passed in to PathFinder.load_module(). I think that's reasonable, since load_module() itself hard-codes sys.path if the supplied path is missing.

I've checked this in to the pep-420 branch. I prefer this approach over Nick's because it doesn't require any changes to any existing interfaces. The changes are contained to the namespace package code and don't affect other code in importlib.

Assuming this approach is acceptable, I'm done with the PEP except for adding some examples.

And I'm done with the implementation except for adding tests and a few small tweaks.

Eric.



More information about the Python-Dev mailing list