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.

Title: BytesWarning in zipimport paths on sys.path
Type: Stage:
Components: Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9
Status: open Resolution:
Dependencies: 47025 Superseder:
Assigned To: Nosy List: andrei.avk, brett.cannon, graingert
Priority: normal Keywords:

Created on 2022-03-15 13:29 by graingert, last changed 2022-04-11 14:59 by admin.

File name Uploaded Description Edit graingert, 2022-03-15 13:29
Messages (3)
msg415245 - (view) Author: Thomas Grainger (graingert) * Date: 2022-03-15 13:29
importing from a bytes zipimport path on sys.path results in a BytesWarning: Comparison between bytes and string

running the reproducer with `python -b` shows:
python -b 
<frozen importlib._bootstrap_external>:1345: BytesWarning: Comparison between bytes and string

see also
msg415643 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2022-03-21 00:11
This warning can be fixed by changing the following line:


        if not path and str(path) == '':

and running `make regen-importlib; make`

Alternatively the change can be:

        if not path and isinstance(path, (str,bytes)):

I'm not sure which is preferable or if some other fix would be better (I don't know much about importlib).

Adding Brett as the expert -- Brett, can you take a look?

Adding a full traceback with -bb argument:

Traceback (most recent call last):
  File "/Users/ak/temp2/", line 29, in <module>
  File "/Users/ak/opensource/cpython4/Lib/", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/Users/ak/temp2/", line 12, in _tmp_path
    yield pathlib.Path(tmp_dir)
  File "/Users/ak/temp2/", line 24, in main
    import module
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1080, in _find_spec
  File "<frozen importlib._bootstrap_external>", line 1493, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1462, in _get_spec
  File "<frozen importlib._bootstrap_external>", line 1418, in _path_importer_cache
BytesWarning: Comparison between bytes and string
msg415721 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2022-03-21 23:00
bpo-47025 is a bigger discussion about bytes paths that probably needs to be resolved first before worrying about zipimport.
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91182
2022-03-21 23:00:44brett.cannonsetmessages: + msg415721
2022-03-21 23:00:18brett.cannonsetdependencies: + bytes do not work on sys.path
2022-03-21 00:11:50andrei.avksetnosy: + brett.cannon, andrei.avk
messages: + msg415643
2022-03-15 13:29:09graingertcreate