Issue 13977: importlib simplification - Python tracker (original) (raw)
Issue13977
Created on 2012-02-09 17:53 by Jim.Jewett, last changed 2022-04-11 14:57 by admin. This issue is now closed.
Messages (2) | ||
---|---|---|
msg152970 - (view) | Author: Jim Jewett (Jim.Jewett) * ![]() |
Date: 2012-02-09 17:53 |
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? | ||
msg153547 - (view) | Author: Brett Cannon (brett.cannon) * ![]() |
Date: 2012-02-17 14:20 |
So I simply swapped out the code and the tests fail. Then I realized why: while the assumption is right, that does not mean that that name passed to __import__() isn't relative and thus shifts what need to be returned (the else clause case). That's why it's a slice off of __name__ based on name itself; name is some funky tail section of __name__ for relative imports. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:57:26 | admin | set | github: 58185 |
2012-02-17 14:20:51 | brett.cannon | set | status: open -> closedresolution: not a bugmessages: + |
2012-02-16 05:05:48 | meador.inge | set | nosy: + meador.inge |
2012-02-10 06:51:49 | eric.snow | set | nosy: + eric.snow |
2012-02-09 17:55:16 | ezio.melotti | set | assignee: brett.cannonstage: needs patchtype: enhancementversions: + Python 3.3 |
2012-02-09 17:53:52 | Jim.Jewett | create |