New submission from Jim Jewett <jimjjew...@gmail.com>:

http://hg.python.org/cpython/file/aba513307f78/Lib/importlib/_bootstrap.py#l974


  974     # The hell that is fromlist ...
  975     if not fromlist:
  976         # Return up to the first dot in 'name'. This is
complicated by the fact
  977         # that 'name' may be relative.
  978         if level == 0:
  979             return sys.modules[name.partition('.')[0]]
  980         elif not name:
  981             return module
  982         else:
  983             cut_off = len(name) - len(name.partition('.')[0])
  984             return sys.modules[module.__name__[:-cut_off]]

If level is 0, should name == module.__name__?

Yes.
 

If so, then I think that simplifies to

   if not name:
       return module
   genericname=module.__name__.rpartition(".")[0]
   return sys.modules[genericname]

Seems right. Can you file a bug and assign it to me?

----------
messages: 152970
nosy: Jim.Jewett, brett.cannon
priority: normal
severity: normal
status: open
title: importlib simplification

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13977>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to