[New-bugs-announce] [issue13977] importlib simplification

Jim Jewett report at bugs.python.org
Thu Feb 9 18:53:55 CET 2012

New submission from Jim Jewett <jimjjewett at gmail.com>:


  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__?


If so, then I think that simplifies to

   if not name:
       return module
   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 <report at bugs.python.org>

More information about the New-bugs-announce mailing list