Skip to content
Myr

open_file hanldes pathlib.Path("-")

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent 41f5b7a · Browse files · 4 files+30 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+30 added−5 removed

  • tests:+18 added−2 removed
  • other:+12 added−3 removed

4 files+30 added−5 removed

modified:src/click/_compat.py+3 added-3 removed
386 unmodified lines
387 atomic: bool = False,388) -> t.Tuple[t.IO, bool]:389 binary = "b" in mode390391 # Standard streams first. These are simple because they don't need392 # special handling for the atomic flag. It's entirely ignored.393 if filename == "-":391 # Standard streams first. These are simple because they ignore the392 # atomic flag. Use fsdecode to handle Path("-").393 if os.fsdecode(filename) == "-":394 if any(m in mode for m in ["w", "a", "x"]):395 if binary:396 return get_binary_stdout(), False397 return get_text_stdout(encoding=encoding, errors=errors), False
230 unmodified lines
modified:tests/test_arguments.py+2 added-2 removed
118 unmodified lines
119 assert result.output == "Hey!"120 assert result.exit_code == 0121122123def test_path_args(runner):123def test_path_allow_dash(runner):124 @click.command()125 @click.argument("input", type=click.Path(dir_okay=False, allow_dash=True))125 @click.argument("input", type=click.Path(allow_dash=True))126 def foo(input):127 click.echo(input)128129 result = runner.invoke(foo, ["-"])
250 unmodified lines
modified:tests/test_utils.py+16 added
318 unmodified lines
319 assert result.exception is None320 assert result.output == "foobar\nmeep\n"321322323def test_open_file_pathlib_dash(runner):324 @click.command()325 @click.argument(326 "filename", type=click.Path(allow_dash=True, path_type=pathlib.Path)327 )328 def cli(filename):329 click.echo(str(type(filename)))330331 with click.open_file(filename) as f:332 click.echo(f.read())333334 result = runner.invoke(cli, ["-"], input="value")335 assert result.exception is None336 assert result.output == "pathlib.Path\nvalue\n"337338339def test_open_file_ignore_errors_stdin(runner):340 @click.command()341 @click.argument("filename")342 def cli(filename):
164 unmodified lines
modified:CHANGES.rst+9 added
1.. currentmodule:: click23Version 8.0.44-------------56Unreleased78- ``open_file`` recognizes ``Path("-")`` as a standard stream, the9 same as the string ``"-"``. :issue:`2106`101112Version 8.0.313-------------1415Released 2021-10-10
928 unmodified lines