nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: pallets/click
Pull request #1517 (2020-03-30 18:28:08)

With prompt, if no input is specified, the return value is not converted to the requested type
If the passed in default is a string but the type parameter is not a string then click should do its best to convert the default to the requested type.

This becomes an issue when using mypy with click.  MyPy will complain if you pass anything but a string for the default.  One option is to do a type ignore but that starts to pollute the code quickly if you have a lot of prompts that expect integer values.  Fixing this also will prevent some accidental bugs where you use different types with your `type` option and your `default`.  Click should do its best to honor the requested type.


Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 03d1cf9..c11d910 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -145,6 +145,9 @@ Unreleased
     passed in as a default value.
     :issue:`549, 736, 764, 921, 1015, 1618`
 -   Fix formatting when ``Command.options_metavar`` is empty. :pr:`1551`
+-   The default value passed to ``prompt`` will be cast to the correct
+    type like an input value would be. :pr:`1517`
+
 
 Version 7.1.2
 -------------
diff --git a/src/click/termui.py b/src/click/termui.py
index 1eb9ed8..84442ee 100644
--- a/src/click/termui.py
+++ b/src/click/termui.py
@@ -16,7 +16,6 @@ from .exceptions import UsageError
 from .globals import resolve_color_default
 from .types import Choice
 from .types import convert_type
-from .types import Path
 from .utils import echo
 from .utils import LazyFile
 
@@ -146,11 +145,8 @@ def prompt(
             if value:
                 break
             elif default is not None:
-                if isinstance(value_proc, Path):
-                    # validate Path default value(exists, dir_okay etc.)
-                    value = default
-                    break
-                return default
+                value = default
+                break
         try:
             result = value_proc(value)
         except UsageError as e:


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
index a588904..a5dfbb8 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -210,6 +210,13 @@ def test_echo_color_flag(monkeypatch, capfd):
     assert out == f"{text}\n"
 
 
+def test_prompt_cast_default(capfd, monkeypatch):
+    monkeypatch.setattr(sys, "stdin", StringIO("\n"))
+    value = click.prompt("value", default="100", type=int)
+    capfd.readouterr()
+    assert type(value) is int
+
+
 @pytest.mark.skipif(WIN, reason="Test too complex to make work windows.")
 def test_echo_writing_to_standard_error(capfd, monkeypatch):
     def emulate_input(text):
Repository: pallets/click
Pull request #1586 (2020-06-15 15:36:01)

Added IntRange min and max preview to --help output
Issue https://github.com/pallets/click/issues/1525  requested to have the following output for using the `--help` flag on options of type IntRange:
```
Usage: test.py [OPTIONS]

  Simple program that greets NAME for a total of COUNT times.

Options:
  --count INTEGER RANGE  Number of greetings.  [default: 1-32 inclusive]
  --help                 Show this message and exit.
```

This can be used like as a regular click user would expect it to:
````python
import click

@click.command()
@click.option("--count",type=click.IntRange(1, 32), show_default=True, default=1, help="Number of greetings.")
def hello(count):
    """Simple program that greets for a total of COUNT times."""
    for _ in range(count):
        click.echo("Hello!")

if __name__ == '__main__':
    hello()
````


Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 5721fd7..6eb180e 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -18,6 +18,8 @@ Unreleased
     :issue:`1582`
 -   If validation fails for a prompt with ``hide_input=True``, the value
     is not shown in the error message. :issue:`1460`
+-   An ``IntRange`` option shows the accepted range in its help text.
+    :issue:`1525`
 
 
 Version 7.1.2
diff --git a/src/click/core.py b/src/click/core.py
index b7124df..87415bd 100644
--- a/src/click/core.py
+++ b/src/click/core.py
@@ -1936,6 +1936,10 @@ class Option(Parameter):
                 default_string = self.default
             extra.append(f"default: {default_string}")
 
+        if isinstance(self.type, IntRange):
+            if self.type.min is not None and self.type.max is not None:
+                extra.append(f"{self.type.min}-{self.type.max} inclusive")
+
         if self.required:
             extra.append("required")
         if extra:


Test patch:
diff --git a/tests/test_options.py b/tests/test_options.py
index 1b9b27e..28990c3 100644
--- a/tests/test_options.py
+++ b/tests/test_options.py
@@ -216,6 +216,16 @@ def test_dynamic_default_help_text(runner):
     assert "(current user)" in result.output
 
 
+def test_intrange_default_help_text(runner):
+    @click.command()
+    @click.option("--count", type=click.IntRange(1, 32), show_default=True, default=1)
+    def cmd(arg):
+        click.echo(arg)
+
+    result = runner.invoke(cmd, ["--help"])
+    assert "1-32 inclusive" in result.output
+
+
 def test_toupper_envvar_prefix(runner):
     @click.command()
     @click.option("--arg")