classification
Title: Have importlib.resources.contents() return an interable instead of an iterator
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: barry, brett.cannon, miss-islington
Priority: normal Keywords: patch

Created on 2018-04-10 00:27 by brett.cannon, last changed 2018-04-30 19:44 by brett.cannon. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 6467 merged brett.cannon, 2018-04-13 22:13
PR 6664 merged miss-islington, 2018-04-30 18:32
Messages (5)
msg315155 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2018-04-10 00:27
If you look at https://github.com/python/cpython/blob/0f914b5b5f6ba186afd7112fc851c97247076f70/Lib/importlib/resources.py#L247 you will notice that the generator for importlib.resources.contents() return an empty list. While the intent was to have no values be returned by contents(), by virtue of being a generator that empty list is actually being returned as a value.
msg315156 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2018-04-10 00:29
Note that this is in the case where a user is asking for the contents of a namespace package (which by definition, can't have resources).

+1 on fixing this API wart.  

Will you @brett.cannon will submit a PR?  I'll do a quick review and then backport the change to the standalone library.
msg315170 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2018-04-10 15:05
I had to stare at it for a while since I knew it was for namespace packages and I'm so used to them returning a magical value to signal that fact, but then realize we don't even support namespace packages so it wasn't magical at all. ;)

And yes, I'll do a PR and make you a reviewer probably this Friday.
msg315959 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2018-04-30 18:31
New changeset 3ab9365dca8438f89b2060cd3eebe00606133dc4 by Brett Cannon in branch 'master':
bpo-33254: do not return an empty list when asking for the contents of a namespace package (GH-6467)
https://github.com/python/cpython/commit/3ab9365dca8438f89b2060cd3eebe00606133dc4
msg315961 - (view) Author: miss-islington (miss-islington) Date: 2018-04-30 19:30
New changeset 2e5fa38c5aaf7630c55ce6dfb8f79df6b3b86076 by Miss Islington (bot) in branch '3.7':
bpo-33254: do not return an empty list when asking for the contents of a namespace package (GH-6467)
https://github.com/python/cpython/commit/2e5fa38c5aaf7630c55ce6dfb8f79df6b3b86076
History
Date User Action Args
2018-04-30 19:44:12brett.cannonsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-04-30 19:30:33miss-islingtonsetnosy: + miss-islington
messages: + msg315961
2018-04-30 18:32:55miss-islingtonsetpull_requests: + pull_request6358
2018-04-30 18:31:54brett.cannonsetmessages: + msg315959
2018-04-20 21:39:33brett.cannonsettitle: importlib.resources.contents() incorrectly yields an empty list -> Have importlib.resources.contents() return an interable instead of an iterator
2018-04-13 22:13:29brett.cannonsetkeywords: + patch
stage: test needed -> patch review
pull_requests: + pull_request6162
2018-04-10 15:05:09brett.cannonsetmessages: + msg315170
2018-04-10 00:29:47barrysetmessages: + msg315156
2018-04-10 00:27:02brett.cannoncreate