This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
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) * (Python triager) | 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) * (Python committer) | 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 -> closed resolution: not a bug messages: + msg153547 |
| 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.cannon stage: needs patch type: enhancement versions: + Python 3.3 |
| 2012年02月09日 17:53:52 | Jim.Jewett | create | |