master.SysModulesMethod: log rejection reasons

pull/913/head
Alex Willmer 3 years ago
parent 0fa0a93f55
commit 47699e15aa

@ -589,23 +589,37 @@ class SysModulesMethod(FinderMethod):
""" """
Find `fullname` using its :data:`__file__` attribute. Find `fullname` using its :data:`__file__` attribute.
""" """
module = sys.modules.get(fullname) try:
module = sys.modules[fullname]
except KeyError:
LOG.debug('%r: sys.modules[%r] absent, aborting', self, fullname)
return
if not isinstance(module, types.ModuleType): if not isinstance(module, types.ModuleType):
LOG.debug('%r: sys.modules[%r] absent or not a regular module', LOG.debug('%r: sys.modules[%r] is %r, aborting',
self, fullname) self, fullname, module)
return
try:
resolved_name = module.__name__
except AttributeError:
LOG.debug('%r: %r has no __name__, aborting', self, module)
return
if resolved_name != fullname:
LOG.debug('%r: %r.__name__ is %r, aborting',
self, module, resolved_name)
return return
LOG.debug('_get_module_via_sys_modules(%r) -> %r', fullname, module) try:
alleged_name = getattr(module, '__name__', None) path = module.__file__
if alleged_name != fullname: except AttributeError:
LOG.debug('sys.modules[%r].__name__ is incorrect, assuming ' LOG.debug('%r: %r has no __file__, aborting', self, module)
'this is a hacky module alias and ignoring it. '
'Got %r, module object: %r',
fullname, alleged_name, module)
return return
path, _ = _py_filename(getattr(module, '__file__', '')) path, _ = _py_filename(path)
if not path: if not path:
LOG.debug('%r: %r.__file__ is %r, aborting', self, module, path)
return return
LOG.debug('%r: sys.modules[%r]: found %s', self, fullname, path) LOG.debug('%r: sys.modules[%r]: found %s', self, fullname, path)

Loading…
Cancel
Save