[New-bugs-announce] [issue47025] bytes do not work on sys.path

Thomas Grainger report at bugs.python.org
Tue Mar 15 06:32:43 EDT 2022

New submission from Thomas Grainger <tagrain at gmail.com>:

importing a module with bytes in `sys.path` fails with:

  File "<frozen importlib._bootstrap_external>", line 182, in _path_isabs
TypeError: startswith first arg must be bytes or a tuple of bytes, not str

(see reproducer in attached demo.py)

however `sys.path` is documented as supporting bytes "Only strings and bytes should be added to sys.path; all other data types are ignored during import." https://docs.python.org/3/library/sys.html?highlight=Only%20strings%20and%20bytes#sys.path

bytes are allowed in PathFinder._find_spec https://github.com/python/cpython/blob/2cf7f865f099db11cc6903b334d9c376610313e8/Lib/importlib/_bootstrap_external.py#L1460-L1462 but perhaps they should be ignored or explicitly fsdecoded ? 

see also:

files: demo.py
messages: 415233
nosy: graingert
priority: normal
severity: normal
status: open
title: bytes do not work on sys.path
Added file: https://bugs.python.org/file50678/demo.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list