Skip to content

[Python forward compat] click.types.Path.covert: BytesWarning: Comparison between bytes and string #2877

Description

@webknjaz

So I've hit this through pip-tools' pip-compile executable some time ago but forgot to report immediately.

I tend to run Python with strictness like python -I -s -E -bb -Werror -m piptools compile --some --args. And that's how I've found this warning. I imagine, it's easy to address by changing the check here: https://github.com/pallets/click/blob/c9f7d9d/src/click/types.py#L929C64-L929C75. Perhaps, by converting the data type.

Here's a minimal repro. In needs a modern enough Python for -bb IIRC.

$ python -Im pip install Click
$ python -bb -Werror
Python 3.12.9 (main, Feb 22 2025, 21:46:24) [GCC 14.2.1 20241221] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from click.types import Path
>>> Path(allow_dash=True).convert('', '', '')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/venv/lib/python3.12/site-packages/click/types.py", line 865, in convert
    is_dash = self.file_okay and self.allow_dash and rv in (b"-", "-")
                                                     ^^^^^^^^^^^^^^^^^
BytesWarning: Comparison between bytes and string

Environment:

  • Python version: 3.12.9
  • Click version: 8.1.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions