Issue 28424: pkgutil.get_data() doesn't work with namespace packages (original) (raw)

Created on 2016-10-12 23:36 by dgreiman, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
namespace_package_get_data.sh dgreiman,2016-10-12 23:36 Unix shell script to demonstrate bug
issue28424.patch dgreiman,2016-12-10 01:39 review
Messages (8)
msg278543 - (view) Author: Douglas Greiman (dgreiman) * Date: 2016-10-12 23:36
pkg_util.get_data('mypackage', 'resourcename') returns None if 'mypackage' is a namespace package, because the package object has no __file__ attribute. A shell script is attached to reproduce this. This is either a bug to be fixed (my preference) or behavior to be documented. If there is equivalent, working functionality in the new importlib, that would also be a good to document.
msg278629 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-10-14 04:06
The doc says: "If the package cannot be located or loaded, or it uses a loader which does not support get_data(), then None is returned". Namespace package gets a ``None`` loader and then does not support get_data.
msg278663 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-10-14 20:00
Xiang is right about why this doesn't work. If you would like to propose a patch to update the wording of the docs, Douglas, we could then consider applying it. It could be as simple as just adding "(e.g. the load for namespace packages does not implement get_data())". And there is no equivalent feature in importlib (yet; it's on my todo list).
msg278699 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2016-10-15 06:55
For 3.4/5/6, I agree this is a documentation issue, where the data files need to be given a *non*-namespaced directory to live in. However, it's worth explicitly noting that subpackages of namespace packages can themselves be regular packages, so one possible solution is to do: pkg_util.get_data('my_namespace.my_package_data', 'resourcename') rather than storing the data directly at the namespace level.
msg282819 - (view) Author: Douglas Greiman (dgreiman) * Date: 2016-12-10 01:39
Patch attached. Feel free to wordsmith.
msg282870 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-12-10 19:55
Patch LGTM.
msg282880 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-12-10 22:15
New changeset 3484933ba904 by Brett Cannon in branch '3.5': Issue #28424: Document pkgutil.get_data() doesn't work with namespace packages. https://hg.python.org/cpython/rev/3484933ba904 New changeset c17d2a37d610 by Brett Cannon in branch '3.6': Merge for issue #28424 https://hg.python.org/cpython/rev/c17d2a37d610 New changeset b396a2c97871 by Brett Cannon in branch 'default': Merge for issue #28424 https://hg.python.org/cpython/rev/b396a2c97871
msg282881 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-12-10 22:15
Thanks for the patch, Douglas!
History
Date User Action Args
2022-04-11 14:58:38 admin set github: 72610
2016-12-10 22:15:53 brett.cannon set status: open -> closedresolution: fixedmessages: +
2016-12-10 22:15:31 python-dev set nosy: + python-devmessages: +
2016-12-10 19:55:40 brett.cannon set versions: + Python 3.7, - Python 3.4
2016-12-10 19:55:07 brett.cannon set messages: + stage: commit review
2016-12-10 01:39:30 dgreiman set files: + issue28424.patchkeywords: + patchmessages: +
2016-10-15 06:55:15 ncoghlan set messages: + versions: + Python 3.6
2016-10-14 20:00:31 brett.cannon set nosy: + docs@pythonmessages: + assignee: docs@pythoncomponents: + Documentation, - Library (Lib)
2016-10-14 04:06:25 xiang.zhang set nosy: + eric.snow, brett.cannon, xiang.zhang, ncoghlanmessages: +
2016-10-13 19:36:56 eric.smith set nosy: + eric.smith
2016-10-12 23:36:00 dgreiman create