]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-91181: drop support for bytes on sys.path (GH-31934)
authorThomas Grainger <tagrain@gmail.com>
Sun, 17 Jul 2022 01:07:53 +0000 (02:07 +0100)
committerGitHub <noreply@github.com>
Sun, 17 Jul 2022 01:07:53 +0000 (18:07 -0700)
Support for bytes broke sometime between Python 3.2 and 3.6 and has been broken ever since. Trying to bring back supports is surprisingly difficult in the face of -b and checking for keys in sys.path_importer_cache. Since the support was broken for so long, trying to overcome the difficulty of bringing back the support has been deemed not worth it.

Co-authored-by: Eryk Sun <eryksun@gmail.com>
Co-authored-by: Brett Cannon <brett@python.org>
Doc/library/sys.rst
Doc/reference/import.rst
Lib/importlib/_bootstrap_external.py
Lib/test/test_zipimport.py
Lib/zipimport.py
Misc/NEWS.d/next/Library/2022-03-16-14-24-14.bpo-47025.qtT3CE.rst [new file with mode: 0644]

index 7e2468446eb96cb249f81aaae259b1c00630fc73..d9799f8358c264b76460fa66bc4bc5cc663acdf9 100644 (file)
@@ -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.
 
 
index 29d402ebcf492aaff107342d1978bd998d4d4639..1e6b08f32a7aca5506188e54ce1e87dca899fdf0 100644 (file)
@@ -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 <path entry
-finder>`.
+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
index 007127b9fd42672925fe0b6b0eb67d2284cb4491..b6c6716e90773418f20dc74c8196ff710001258b 100644 (file)
@@ -1475,7 +1475,7 @@ class PathFinder:
         #  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:
index fd2739dd89ac064459ea741f4d5ba1d9aa846123..52d43bdead67f8efecf123c76944006c26b14a86 100644 (file)
@@ -742,7 +742,8 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
             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):
index d0394107c2c5facbf8ab518d31b24eb31c0b227c..016f1b8a79798849ea41b486bcf86c90f31117c0 100644 (file)
@@ -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 (file)
index 0000000..1c7c7ac
--- /dev/null
@@ -0,0 +1 @@
+Drop support for :class:`bytes` on :attr:`sys.path`.