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

Created on 2018-04-10 00:27 by brett.cannon, last changed 2018-04-20 21:39 by brett.cannon.

Pull Requests
URL Status Linked Edit
PR 6467 open brett.cannon, 2018-04-13 22:13
Messages (3)
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.
History
Date User Action Args
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