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年05月03日 10:45 by Pavel.Aslanov, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| python_pkgutil_bug.patch | Pavel.Aslanov, 2012年05月03日 10:45 | |||
| Messages (9) | |||
|---|---|---|---|
| msg159848 - (view) | Author: Pavel Aslanov (Pavel.Aslanov) | Date: 2012年05月03日 10:45 | |
if module was marked as not existing by setting sys.modules [fullname] to None, then pkgutil.get_loader (fullname) will throw AttributeError.
Example:
#! /usr/bin/evn python
import unittest
import pkgutil
def main ():
pkgutil.get_loader ('unittest.functools')
if __name__ == '__main__':
main ()
Patch is attached
|
|||
| msg159861 - (view) | Author: Brett Cannon (brett.cannon) * (Python committer) | Date: 2012年05月03日 15:19 | |
So I'm no pkgutil expert, but at least in the case of None in sys.modules, that triggers at least an ImportError in __import__ if that is come across. |
|||
| msg159900 - (view) | Author: Pavel Aslanov (Pavel.Aslanov) | Date: 2012年05月04日 04:17 | |
Main use case of pkgutil.get_loader is to determine if its possible to load module and either return loader or None. But it throws exception more over it is AttributeErrror exception. |
|||
| msg159901 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2012年05月04日 04:36 | |
I'm not yet sure the proposed fix in the patch is the right approach (I need to look at the surrounding code), but I believe Pavel's right that get_loader() should be returning None in this case instead of throwing an exception. |
|||
| msg215168 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2014年03月30日 05:58 | |
Update as of Python 3.4: pkgutil.get_loader() still throws AttributeError for this case, but importlib.util.find_spec() returns None as expected. |
|||
| msg218789 - (view) | Author: Pavel Aslanov (Pavel.Aslanov) | Date: 2014年05月19日 11:14 | |
This function is broken again in version 3.4
The way it should look is:
Python 2.7.6 (default, Feb 26 2014, 12:07:17)
[GCC 4.8.2 20140206 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkgutil
>>> pkgutil.get_loader('no_such_module') # returns None
>>>
How it really looks:
Python 3.4.0 (default, Apr 27 2014, 23:33:09)
[GCC 4.8.2 20140206 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkgutil
>>> pkgutil.get_loader('no_such_module')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/pkgutil.py", line 467, in get_loader
return find_loader(fullname)
File "/usr/lib/python3.4/pkgutil.py", line 488, in find_loader
return spec.loader
AttributeError: 'NoneType' object has no attribute 'loader'
>>>
find_loader is at fault (change "return spec.loader" -> "return spec and spec.loader"). Thanks.
|
|||
| msg218803 - (view) | Author: Brett Cannon (brett.cannon) * (Python committer) | Date: 2014年05月19日 17:46 | |
I'll take a look the next time I have some Python time (in a week or two) and make sure this gets dealt with. |
|||
| msg218977 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2014年05月23日 16:32 | |
New changeset 660c82192c69 by Brett Cannon in branch '3.4': Issue #14710: Fix both pkgutil.find_loader() and get_loader() to not http://hg.python.org/cpython/rev/660c82192c69 New changeset 1adc8eb362f0 by Brett Cannon in branch 'default': Merge for issue #14710 http://hg.python.org/cpython/rev/1adc8eb362f0 |
|||
| msg218978 - (view) | Author: Brett Cannon (brett.cannon) * (Python committer) | Date: 2014年05月23日 16:33 | |
Thanks for the bug report, Pavel. It turned out pkgutil.find_loader is broken as well as pkgutil.get_loader in different ways. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:29 | admin | set | github: 58915 |
| 2014年05月23日 16:33:33 | brett.cannon | set | status: open -> closed messages: + msg218978 stage: resolved |
| 2014年05月23日 16:32:42 | python-dev | set | nosy:
+ python-dev messages: + msg218977 |
| 2014年05月23日 16:27:59 | brett.cannon | set | versions: - Python 2.7 |
| 2014年05月23日 16:27:49 | brett.cannon | set | title: pkgutil.get_loader is broken -> pkgutil.get_loader and find_loader fail when module is missing |
| 2014年05月19日 19:07:59 | eric.snow | set | nosy:
+ eric.snow |
| 2014年05月19日 17:46:34 | brett.cannon | set | assignee: brett.cannon messages: + msg218803 |
| 2014年05月19日 11:14:37 | Pavel.Aslanov | set | messages: + msg218789 |
| 2014年03月30日 05:58:01 | ncoghlan | set | messages:
+ msg215168 versions: + Python 3.4, Python 3.5 |
| 2012年05月04日 16:38:04 | eric.araujo | set | nosy:
+ eric.araujo |
| 2012年05月04日 04:41:48 | Arfrever | set | nosy:
+ Arfrever |
| 2012年05月04日 04:36:28 | ncoghlan | set | messages: + msg159901 |
| 2012年05月04日 04:17:18 | Pavel.Aslanov | set | messages: + msg159900 |
| 2012年05月03日 15:19:27 | brett.cannon | set | messages: + msg159861 |
| 2012年05月03日 10:54:44 | pitrou | set | nosy:
+ brett.cannon, ncoghlan |
| 2012年05月03日 10:45:40 | Pavel.Aslanov | create | |