Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/click/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,13 @@ def convert(
) -> str | bytes | os.PathLike[str]:
rv = value

is_dash = self.file_okay and self.allow_dash and rv in (b"-", "-")
if self.file_okay and self.allow_dash:
if isinstance(rv, bytes):
is_dash = rv == b"-"
else:
is_dash = rv == "-"
else:
is_dash = False

if not is_dash:
if self.resolve_path:
Expand Down
23 changes: 23 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os.path
import pathlib
import platform
import subprocess
import sys
import tempfile

import pytest
Expand Down Expand Up @@ -106,6 +108,27 @@ def test_path_type(runner, cls, expect):
assert result.return_value == expect


def test_path_bytes_dash_no_byteswarning():
code = (
"from click.types import Path; Path(allow_dash=True).convert(b'-', None, None)"
)

result = subprocess.run(
[
sys.executable,
"-bb",
"-c",
code,
],
cwd=pathlib.Path(__file__).resolve().parents[1],
env={**os.environ, "PYTHONPATH": "src"},
capture_output=True,
text=True,
)

assert result.returncode == 0, result.stderr


def _symlinks_supported():
with tempfile.TemporaryDirectory(prefix="click-pytest-") as tempdir:
target = os.path.join(tempdir, "target")
Expand Down