From 875b3d84b3072b2d3c352ad9f0ff52c441fbd12e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 21 May 2021 13:00:40 -0400 Subject: bpo-43643: Sync with python/importlib_resources@c17a610aad. (GH-26284) * bpo-43643: Sync with python/importlib_resources@c17a610aad. * Sync with python/importlib_resources@89fd5e961a. --- Lib/importlib/_common.py | 3 ++- Lib/importlib/readers.py | 1 + Lib/test/test_importlib/test_reader.py | 6 ++++++ Misc/NEWS.d/next/Library/2021-05-21-12-12-35.bpo-43643.GWnmcF.rst | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2021-05-21-12-12-35.bpo-43643.GWnmcF.rst diff --git a/Lib/importlib/_common.py b/Lib/importlib/_common.py index 0338304..ed50997 100644 --- a/Lib/importlib/_common.py +++ b/Lib/importlib/_common.py @@ -7,7 +7,7 @@ import types import importlib from typing import Union, Any, Optional -from .abc import ResourceReader +from .abc import ResourceReader, Traversable from ._adapters import wrap_spec @@ -15,6 +15,7 @@ Package = Union[types.ModuleType, str] def files(package): + # type: (Package) -> Traversable """ Get a Traversable resource from a package """ diff --git a/Lib/importlib/readers.py b/Lib/importlib/readers.py index 535c828..3e91c1c 100644 --- a/Lib/importlib/readers.py +++ b/Lib/importlib/readers.py @@ -96,6 +96,7 @@ class MultiplexedPath(abc.Traversable): def open(self, *args, **kwargs): raise FileNotFoundError('{} is not a file'.format(self)) + @property def name(self): return self._paths[0].name diff --git a/Lib/test/test_importlib/test_reader.py b/Lib/test/test_importlib/test_reader.py index b0bf49b..ed1f6be 100644 --- a/Lib/test/test_importlib/test_reader.py +++ b/Lib/test/test_importlib/test_reader.py @@ -82,6 +82,12 @@ class MultiplexedPathTest(unittest.TestCase): "MultiplexedPath('{}')".format(self.folder), ) + def test_name(self): + self.assertEqual( + MultiplexedPath(self.folder).name, + os.path.basename(self.folder), + ) + class NamespaceReaderTest(unittest.TestCase): site_dir = str(pathlib.Path(__file__).parent) diff --git a/Misc/NEWS.d/next/Library/2021-05-21-12-12-35.bpo-43643.GWnmcF.rst b/Misc/NEWS.d/next/Library/2021-05-21-12-12-35.bpo-43643.GWnmcF.rst new file mode 100644 index 0000000..57157df --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-05-21-12-12-35.bpo-43643.GWnmcF.rst @@ -0,0 +1 @@ +Declare readers.MultiplexedPath.name as a property per the spec. -- cgit v0.12