This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author graingert
Recipients graingert
Date 2022-03-15.10:32:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1647340363.27.0.242980103727.issue47025@roundup.psfhosted.org>
In-reply-to
Content
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:
https://bugs.python.org/issue32642
https://github.com/python/importlib_metadata/issues/372#issuecomment-1067799424
History
Date User Action Args
2022-03-15 10:32:43graingertsetrecipients: + graingert
2022-03-15 10:32:43graingertsetmessageid: <1647340363.27.0.242980103727.issue47025@roundup.psfhosted.org>
2022-03-15 10:32:43graingertlinkissue47025 messages
2022-03-15 10:32:43graingertcreate