99from io import BytesIO , TextIOWrapper
1010from pathlib import Path
1111from types import ModuleType
12- from typing import Iterator , Optional , Set , Union # noqa: F401
12+ from typing import Iterable , Iterator , Optional , Set , Union # noqa: F401
1313from typing import cast
1414from typing .io import BinaryIO , TextIO
1515from zipimport import ZipImportError
@@ -44,8 +44,7 @@ def _normalize_path(path) -> str:
4444
4545 If the resulting string contains path separators, an exception is raised.
4646 """
47- str_path = str (path )
48- parent , file_name = os .path .split (str_path )
47+ parent , file_name = os .path .split (path )
4948 if parent :
5049 raise ValueError ('{!r} must be only a file name' .format (path ))
5150 else :
@@ -228,8 +227,8 @@ def is_resource(package: Package, name: str) -> bool:
228227 return path .is_file ()
229228
230229
231- def contents (package : Package ) -> Iterator [str ]:
232- """Return the list of entries in 'package'.
230+ def contents (package : Package ) -> Iterable [str ]:
231+ """Return an iterable of entries in 'package'.
233232
234233 Note that not all entries are resources. Specifically, directories are
235234 not considered resources. Use `is_resource()` on each entry returned here
@@ -238,15 +237,15 @@ def contents(package: Package) -> Iterator[str]:
238237 package = _get_package (package )
239238 reader = _get_resource_reader (package )
240239 if reader is not None :
241- yield from reader .contents ()
242- return
240+ return reader .contents ()
243241 # Is the package a namespace package? By definition, namespace packages
244242 # cannot have resources. We could use _check_location() and catch the
245243 # exception, but that's extra work, so just inline the check.
246- if package .__spec__ .origin is None or not package .__spec__ .has_location :
247- return []
248- package_directory = Path (package .__spec__ .origin ).parent
249- yield from os .listdir (str (package_directory ))
244+ elif package .__spec__ .origin is None or not package .__spec__ .has_location :
245+ return ()
246+ else :
247+ package_directory = Path (package .__spec__ .origin ).parent
248+ return os .listdir (package_directory )
250249
251250
252251# Private implementation of ResourceReader and get_resource_reader() for
0 commit comments