Skip to content
Merged
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
10 changes: 10 additions & 0 deletions _python_utils_tests/test_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ def test_scale_1024_small_number(value: float) -> None:
def test_scale_1024_without_prefixes(n_prefixes: int) -> None:
"""Never return a negative power when there are no prefixes."""
assert converters.scale_1024(2048, n_prefixes) == (2048.0, 0)


@pytest.mark.parametrize('default', [0.0, -1.25])
def test_to_float_float_default(default: float) -> None:
"""Accept the documented float fallback in typed consumer code."""
assert converters.to_float('missing', default=default) is default
assert (
converters.to_float('missing', default=default, regexp=True) is default
)
assert converters.to_float('1.5', default=default) == 1.5
2 changes: 1 addition & 1 deletion python_utils/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def to_int(

def to_float(
input_: str,
default: int = 0,
default: _aliases.Number = 0,
exception: _aliases.ExceptionsType = (ValueError, TypeError),
regexp: _RegexpType = None,
) -> _aliases.Number:
Expand Down
Loading