mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-91181: drop support for bytes on sys.path (GH-31934)
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>
This commit is contained in:
parent
2e9da8e352
commit
6da988a46c
6 changed files with 8 additions and 9 deletions
|
@ -1158,7 +1158,7 @@ always available.
|
||||||
line option or the :envvar:`PYTHONSAFEPATH` environment variable?
|
line option or the :envvar:`PYTHONSAFEPATH` environment variable?
|
||||||
|
|
||||||
A program is free to modify this list for its own purposes. Only strings
|
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.
|
ignored during import.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -800,10 +800,8 @@ environment variable and various other installation- and
|
||||||
implementation-specific defaults. Entries in :data:`sys.path` can name
|
implementation-specific defaults. Entries in :data:`sys.path` can name
|
||||||
directories on the file system, zip files, and potentially other "locations"
|
directories on the file system, zip files, and potentially other "locations"
|
||||||
(see the :mod:`site` module) that should be searched for modules, such as
|
(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
|
URLs, or database queries. Only strings should be present on
|
||||||
:data:`sys.path`; all other data types are ignored. The encoding of bytes
|
:data:`sys.path`; all other data types are ignored.
|
||||||
entries is determined by the individual :term:`path entry finders <path entry
|
|
||||||
finder>`.
|
|
||||||
|
|
||||||
The :term:`path based finder` is a :term:`meta path finder`, so the import
|
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
|
machinery begins the :term:`import path` search by calling the path
|
||||||
|
|
|
@ -1475,7 +1475,7 @@ class PathFinder:
|
||||||
# the list of paths that will become its __path__
|
# the list of paths that will become its __path__
|
||||||
namespace_path = []
|
namespace_path = []
|
||||||
for entry in path:
|
for entry in path:
|
||||||
if not isinstance(entry, (str, bytes)):
|
if not isinstance(entry, str):
|
||||||
continue
|
continue
|
||||||
finder = cls._path_importer_cache(entry)
|
finder = cls._path_importer_cache(entry)
|
||||||
if finder is not None:
|
if finder is not None:
|
||||||
|
|
|
@ -742,7 +742,8 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
|
||||||
z.writestr(zinfo, test_src)
|
z.writestr(zinfo, test_src)
|
||||||
|
|
||||||
zipimport.zipimporter(filename)
|
zipimport.zipimporter(filename)
|
||||||
zipimport.zipimporter(os.fsencode(filename))
|
with self.assertRaises(TypeError):
|
||||||
|
zipimport.zipimporter(os.fsencode(filename))
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
zipimport.zipimporter(bytearray(os.fsencode(filename)))
|
zipimport.zipimporter(bytearray(os.fsencode(filename)))
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
|
|
|
@ -63,8 +63,7 @@ class zipimporter(_bootstrap_external._LoaderBasics):
|
||||||
# if found, or else read it from the archive.
|
# if found, or else read it from the archive.
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
if not isinstance(path, str):
|
if not isinstance(path, str):
|
||||||
import os
|
raise TypeError(f"expected str, not {type(path)!r}")
|
||||||
path = os.fsdecode(path)
|
|
||||||
if not path:
|
if not path:
|
||||||
raise ZipImportError('archive path is empty', path=path)
|
raise ZipImportError('archive path is empty', path=path)
|
||||||
if alt_path_sep:
|
if alt_path_sep:
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Drop support for :class:`bytes` on :attr:`sys.path`.
|
Loading…
Add table
Add a link
Reference in a new issue