importer: reorder/tweak find_module() tests to cope with six.moves

The old hack on the master side we had is broken for some reason on 3.x.
Instead tweak the client to be more selective: if a request is for a
module within a package, the package must be loaded (in sys.modules),
and its __loader__ must be us. Previously if the module didn't exist in
sys.modules, we'd still try to fetch from the master, which doesn't
appear to ever make sense.
pull/295/head
David Wilson 7 years ago
parent 826c477061
commit 9fb2371d64

@ -682,27 +682,25 @@ class Importer(object):
_tls.running = True
try:
pkgname, dot, _ = fullname.rpartition('.')
_vv and IOLOG.debug('%r.find_module(%r)', self, fullname)
suffix = fullname[len(pkgname+dot):]
if suffix not in self._present.get(pkgname, (suffix,)):
_v and LOG.debug('%r: master doesn\'t know %r', self, fullname)
return None
pkg = sys.modules.get(pkgname)
if pkg and getattr(pkg, '__loader__', None) is not self:
_vv and IOLOG.debug(
'%r: %r is submodule of a package we did not load',
self, fullname
)
return None
_v and LOG.debug('%r.find_module(%r)', self, fullname)
# #114: explicitly whitelisted prefixes override any
# system-installed package.
if self.whitelist != ['']:
if any(fullname.startswith(s) for s in self.whitelist):
return self
pkgname, dot, _ = fullname.rpartition('.')
pkg = sys.modules.get(pkgname)
if pkgname and getattr(pkg, '__loader__', None) is not self:
LOG.debug('%r: %r is submodule of a package we did not load',
self, fullname)
return None
suffix = fullname[len(pkgname+dot):]
if pkgname and suffix not in self._present.get(pkgname, ()):
_v and LOG.debug('%r: master doesn\'t know %r', self, fullname)
return None
try:
self.builtin_find_module(fullname)
_vv and IOLOG.debug('%r: %r is available locally',

@ -471,7 +471,7 @@ class ModuleFinder(object):
for name in maybe_names
if sys.modules.get(name) is not None
and not is_stdlib_name(name)
and 'six.moves' not in name # TODO: crap
and u'six.moves' not in name # TODO: crap
)
))

Loading…
Cancel
Save