-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: remove bytes comparison in Path.convert to avoid BytesWarning #3249
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,6 +136,22 @@ def foo(input): | |
| assert result.exit_code == 0 | ||
|
|
||
|
|
||
| def test_path_allow_dash_no_bytes_warning(runner): | ||
| """Path with allow_dash should not compare str against bytes.""" | ||
| import warnings | ||
|
|
||
| @click.command() | ||
| @click.argument("input", type=click.Path(allow_dash=True)) | ||
| def foo(input): | ||
| click.echo(input) | ||
|
|
||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("error", BytesWarning) | ||
| result = runner.invoke(foo, ["-"]) | ||
| assert result.exit_code == 0 | ||
|
Comment on lines
+139
to
+151
|
||
| assert result.output == "-\n" | ||
|
|
||
|
|
||
| def test_file_atomics(runner): | ||
| @click.command() | ||
| @click.argument("output", type=click.File("wb", atomic=True)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rv == "-"avoids thestrvsbytestuple membership warning, but ifvalueis ever abytespath (e.g. passed programmatically or viaCliRunner.invokewithbytesargs), this comparison will still emitBytesWarningunder-bb. Usingos.fsdecode(rv) == "-"for the dash check would avoid anybytes/strcomparison and matches the approach used inopen_streamfor handlingPath("-").