Skip to content

Commit 2a96da0

Browse files
authored
Fix handling of integers in AutoIntParamType (#206)
* Fix AutoIntParamType definition * Bump the version
1 parent 395bc0e commit 2a96da0

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ build-backend = "poetry.masonry.api"
1212

1313
[tool.poetry]
1414
name = "together"
15-
version = "1.3.2"
15+
version = "1.3.3"
1616
authors = [
1717
"Together AI <[email protected]>"
1818
]

src/together/cli/api/utils.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
from __future__ import annotations
22

3-
import click
4-
3+
from gettext import gettext as _
54
from typing import Literal
65

6+
import click
7+
78

89
class AutoIntParamType(click.ParamType):
9-
name = "integer"
10+
name = "integer_or_max"
11+
_number_class = int
1012

1113
def convert(
1214
self, value: str, param: click.Parameter | None, ctx: click.Context | None
1315
) -> int | Literal["max"] | None:
14-
if isinstance(value, int):
15-
return value
16-
1716
if value == "max":
1817
return "max"
19-
20-
self.fail("Invalid integer value: {value}")
18+
try:
19+
return int(value)
20+
except ValueError:
21+
self.fail(
22+
_("{value!r} is not a valid {number_type}.").format(
23+
value=value, number_type=self.name
24+
),
25+
param,
26+
ctx,
27+
)
2128

2229

2330
INT_WITH_MAX = AutoIntParamType()

0 commit comments

Comments
 (0)