diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 7e2468446eb96c..d9799f8358c264 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1158,7 +1158,7 @@ always available. line option or the :envvar:`PYTHONSAFEPATH` environment variable? A program is free to modify this list for its own purposes. Only strings - and bytes should be added to :data:`sys.path`; all other data types are + should be added to :data:`sys.path`; all other data types are ignored during import. diff --git a/Doc/reference/import.rst b/Doc/reference/import.rst index 29d402ebcf492a..1e6b08f32a7aca 100644 --- a/Doc/reference/import.rst +++ b/Doc/reference/import.rst @@ -800,10 +800,8 @@ environment variable and various other installation- and implementation-specific defaults. Entries in :data:`sys.path` can name directories on the file system, zip files, and potentially other "locations" (see the :mod:`site` module) that should be searched for modules, such as -URLs, or database queries. Only strings and bytes should be present on -:data:`sys.path`; all other data types are ignored. The encoding of bytes -entries is determined by the individual :term:`path entry finders `. +URLs, or database queries. Only strings should be present on +:data:`sys.path`; all other data types are ignored. The :term:`path based finder` is a :term:`meta path finder`, so the import machinery begins the :term:`import path` search by calling the path diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index 446d7981acbab5..f603a89f7f5a98 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -1468,7 +1468,7 @@ def _get_spec(cls, fullname, path, target=None): # the list of paths that will become its __path__ namespace_path = [] for entry in path: - if not isinstance(entry, (str, bytes)): + if not isinstance(entry, str): continue finder = cls._path_importer_cache(entry) if finder is not None: diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py index 84995be3295682..59a520015ff3a2 100644 --- a/Lib/test/test_zipimport.py +++ b/Lib/test/test_zipimport.py @@ -758,7 +758,8 @@ def testBytesPath(self): z.writestr(zinfo, test_src) zipimport.zipimporter(filename) - zipimport.zipimporter(os.fsencode(filename)) + with self.assertRaises(TypeError): + zipimport.zipimporter(os.fsencode(filename)) with self.assertRaises(TypeError): zipimport.zipimporter(bytearray(os.fsencode(filename))) with self.assertRaises(TypeError): diff --git a/Lib/zipimport.py b/Lib/zipimport.py index 25eaee9c0f291b..225bd214d627c5 100644 --- a/Lib/zipimport.py +++ b/Lib/zipimport.py @@ -63,8 +63,7 @@ class zipimporter(_bootstrap_external._LoaderBasics): # if found, or else read it from the archive. def __init__(self, path): if not isinstance(path, str): - import os - path = os.fsdecode(path) + raise TypeError(f"expected str, not {type(path)!r}") if not path: raise ZipImportError('archive path is empty', path=path) if alt_path_sep: diff --git a/Misc/NEWS.d/next/Library/2022-03-16-14-24-14.bpo-47025.qtT3CE.rst b/Misc/NEWS.d/next/Library/2022-03-16-14-24-14.bpo-47025.qtT3CE.rst new file mode 100644 index 00000000000000..1c7c7ace9706d7 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-03-16-14-24-14.bpo-47025.qtT3CE.rst @@ -0,0 +1 @@ +Drop support for :class:`bytes` on :attr:`sys.path`.