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

BytesWarning in zipimport paths on sys.path #91182

Closed
graingert mannequin opened this issue Mar 15, 2022 · 4 comments
Closed

BytesWarning in zipimport paths on sys.path #91182

graingert mannequin opened this issue Mar 15, 2022 · 4 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir

Comments

@graingert
Copy link
Mannequin

graingert mannequin commented Mar 15, 2022

BPO 47026
Nosy @brettcannon, @graingert, @akulakov
Dependencies
  • bpo-47025: bytes do not work on sys.path
  • Files
  • zipfile_demo.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2022-03-15.13:29:09.171>
    labels = ['library', '3.9', '3.10', '3.11']
    title = 'BytesWarning in zipimport paths on sys.path'
    updated_at = <Date 2022-03-21.23:00:44.042>
    user = 'https://github.com/graingert'

    bugs.python.org fields:

    activity = <Date 2022-03-21.23:00:44.042>
    actor = 'brett.cannon'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2022-03-15.13:29:09.171>
    creator = 'graingert'
    dependencies = ['47025']
    files = ['50680']
    hgrepos = []
    issue_num = 47026
    keywords = []
    message_count = 3.0
    messages = ['415245', '415643', '415721']
    nosy_count = 3.0
    nosy_names = ['brett.cannon', 'graingert', 'andrei.avk']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue47026'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @graingert
    Copy link
    Mannequin Author

    graingert mannequin commented Mar 15, 2022

    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 zipfile_demo.py
    :1345: BytesWarning: Comparison between bytes and string

    see also https://bugs.python.org/issue47025

    @graingert graingert mannequin added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir labels Mar 15, 2022
    @akulakov
    Copy link
    Contributor

    This warning can be fixed by changing the following line:

    to:

            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/zipfile_demo.py", line 29, in <module>
        sys.exit(main())
                 ^^^^^^
      File "/Users/ak/opensource/cpython4/Lib/contextlib.py", line 155, in __exit__
        self.gen.throw(typ, value, traceback)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/ak/temp2/zipfile_demo.py", line 12, in _tmp_path
        yield pathlib.Path(tmp_dir)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/ak/temp2/zipfile_demo.py", 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

    @brettcannon
    Copy link
    Member

    bpo-47025 is a bigger discussion about bytes paths that probably needs to be resolved first before worrying about zipimport.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @serhiy-storchaka
    Copy link
    Member

    The support of bytes paths was completely dropped in bpo-47025 (gh-91181).

    @serhiy-storchaka serhiy-storchaka closed this as not planned Won't fix, can't repro, duplicate, stale Jul 5, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants