From 2a96da09bfb7db652fb48cbb9a7039d8cca9c909 Mon Sep 17 00:00:00 2001 From: Max Ryabinin Date: Fri, 18 Oct 2024 19:59:46 +0200 Subject: [PATCH] Fix handling of integers in AutoIntParamType (#206) * Fix AutoIntParamType definition * Bump the version --- pyproject.toml | 2 +- src/together/cli/api/utils.py | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 673f4887..a29fba8b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ build-backend = "poetry.masonry.api" [tool.poetry] name = "together" -version = "1.3.2" +version = "1.3.3" authors = [ "Together AI " ] diff --git a/src/together/cli/api/utils.py b/src/together/cli/api/utils.py index 721412d7..3f85f380 100644 --- a/src/together/cli/api/utils.py +++ b/src/together/cli/api/utils.py @@ -1,23 +1,30 @@ from __future__ import annotations -import click - +from gettext import gettext as _ from typing import Literal +import click + class AutoIntParamType(click.ParamType): - name = "integer" + name = "integer_or_max" + _number_class = int def convert( self, value: str, param: click.Parameter | None, ctx: click.Context | None ) -> int | Literal["max"] | None: - if isinstance(value, int): - return value - if value == "max": return "max" - - self.fail("Invalid integer value: {value}") + try: + return int(value) + except ValueError: + self.fail( + _("{value!r} is not a valid {number_type}.").format( + value=value, number_type=self.name + ), + param, + ctx, + ) INT_WITH_MAX = AutoIntParamType()