Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.11] gh-91181: drop support for bytes on sys.path (GH-31934) #94914

Merged
merged 1 commit into from
Jul 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/library/sys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
6 changes: 2 additions & 4 deletions Doc/reference/import.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_zipimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions Lib/zipimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Drop support for :class:`bytes` on :attr:`sys.path`.