mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-01-19 21:40:24 +00:00
feat: Improved typing, exception if neither step nor decimals is set
This commit is contained in:
@@ -8,7 +8,7 @@ class SKDecimal(FloatDistribution):
|
||||
high: float,
|
||||
*,
|
||||
step: float | None = None,
|
||||
decimals: int = 3,
|
||||
decimals: int | None = None,
|
||||
name=None,
|
||||
):
|
||||
"""
|
||||
@@ -22,6 +22,8 @@ class SKDecimal(FloatDistribution):
|
||||
"""
|
||||
if decimals is not None and step is not None:
|
||||
raise ValueError("You can only set one of decimals or step")
|
||||
if decimals is None and step is None:
|
||||
raise ValueError("You must set one of decimals or step")
|
||||
# Convert decimals to step
|
||||
self.step = step or 1 / 10**decimals
|
||||
self.name = name
|
||||
|
||||
@@ -1197,6 +1197,9 @@ def test_SKDecimal():
|
||||
with pytest.raises(ValueError):
|
||||
SKDecimal(1, 2, step=5, decimals=0.2)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
SKDecimal(1, 2, step=None, decimals=None)
|
||||
|
||||
s = SKDecimal(1, 2, step=0.1, decimals=None)
|
||||
assert s.step == 0.1
|
||||
assert s._contains(1.1)
|
||||
|
||||
Reference in New Issue
Block a user