Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
Fix python definition for input.slider, require min/max and fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobmischka committed Jul 13, 2023
1 parent 77fef3b commit 61678d7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
15 changes: 15 additions & 0 deletions src/demos/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,21 @@ async def hello_interval():
return {"hello": "from python!"}


@interval.action
async def default_slider(io: IO):
nint = await io.input.slider("Ints", min=0, max=10)
nfloat = await io.input.slider("Floats", min=0.0, max=1.0, step=0.1)
ndefault = await io.input.slider("Default", min=0, max=10, default_value=2.0)

print(nint, nfloat, ndefault)

return {
"nint": nint,
"nfloat": nfloat,
"ndefault": ndefault,
}


async def manual_action_handler(io: IO):
await io.display.markdown("IO works!")

Expand Down
27 changes: 16 additions & 11 deletions src/interval_sdk/classes/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@ def slider(
self,
label: str,
*,
min: Optional[Union[float, int]] = None,
max: Optional[Union[float, int]] = None,
min: int,
max: int,
step: Optional[int] = None,
help_text: Optional[str] = None,
default_value: Optional[Union[float, int]] = None,
default_value: Optional[int] = None,
disabled: Optional[bool] = None,
) -> InputIOPromise[Literal["INPUT_SLIDER"], int]:
...
Expand All @@ -298,21 +298,21 @@ def slider(
self,
label: str,
*,
min: Optional[Union[float, int]] = None,
max: Optional[Union[float, int]] = None,
step: Optional[float] = None,
min: Union[int, float],
max: Union[int, float],
step: Optional[Union[int, float]] = None,
help_text: Optional[str] = None,
default_value: Optional[Union[float, int]] = None,
default_value: Optional[Union[int, float]] = None,
disabled: Optional[bool] = None,
) -> InputIOPromise[Literal["INPUT_SLIDER"], int]:
) -> InputIOPromise[Literal["INPUT_SLIDER"], float]:
...

def slider(
self,
label: str,
*,
min: Optional[Union[float, int]] = None,
max: Optional[Union[float, int]] = None,
min: Union[float, int],
max: Union[float, int],
step: Optional[Union[float, int]] = None,
help_text: Optional[str] = None,
default_value: Optional[Union[float, int]] = None,
Expand All @@ -333,7 +333,12 @@ def slider(
)

def get_value(val: float):
if step is None or isinstance(step, int):
if (
isinstance(min, int)
and isinstance(max, int)
and (step is None or isinstance(step, int))
and (default_value is None or isinstance(default_value, int))
):
return int(val)

return val
Expand Down
4 changes: 2 additions & 2 deletions src/interval_sdk/io_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,8 @@ class InputNumberProps(BaseModel):


class InputSliderProps(BaseModel):
min: Optional[Union[float, int]]
max: Optional[Union[float, int]]
min: Union[float, int]
max: Union[float, int]
step: Optional[Union[float, int]]
help_text: Optional[str]
default_value: Optional[Union[float, int]]
Expand Down

0 comments on commit 61678d7

Please sign in to comment.