Skip to content

Fix BytesWarning in Path.convert when comparing bytes and str#3322

Closed
internet-dot wants to merge 1 commit intopallets:mainfrom
internet-dot:fix/path-bytes-warning
Closed

Fix BytesWarning in Path.convert when comparing bytes and str#3322
internet-dot wants to merge 1 commit intopallets:mainfrom
internet-dot:fix/path-bytes-warning

Conversation

@internet-dot
Copy link
Copy Markdown

When allow_dash=True and rv is bytes, the check rv in (b"-", "-") raises BytesWarning under -bb mode because Python compares bytes against str.

Fix by adding an isinstance check before the containment test so that bytes rv is only compared against bytes "-" and str rv against str "-".

Fixes #2877

When allow_dash=True and rv is bytes, the check rv in (b'-', '-')
raises BytesWarning under -bb mode because Python compares bytes
against str. Fix by short-circuiting with isinstance check before
the containment test.

Fixes pallets#2877
@davidism davidism closed this Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants