From 6fcf87e82f6ba836b577966c30ba1442e581fc6d Mon Sep 17 00:00:00 2001 From: Sujata R <135149476+sroycho4@users.noreply.github.com> Date: Wed, 15 Nov 2023 04:59:56 +0000 Subject: [PATCH 1/2] deleted comments --- tests/test_files.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_files.py b/tests/test_files.py index 15d5c6a811..17c65584ab 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -46,6 +46,6 @@ def test_string_not_allowed() -> None: with pytest.raises(TypeError, match="Expected file types input to be a FileContent type or to be a tuple"): to_httpx_files( { - "file": "foo", # type: ignore + "file": "foo", } ) From 54759af52e0deea9467b090ab194060869da0a51 Mon Sep 17 00:00:00 2001 From: Sujata R <135149476+sroycho4@users.noreply.github.com> Date: Wed, 6 Dec 2023 12:32:32 +0530 Subject: [PATCH 2/2] Made code changes, made it clean and short for easy understanding --- src/openai/cli/_progress.py | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/openai/cli/_progress.py b/src/openai/cli/_progress.py index 390aaa9dfe..810b58c9f5 100644 --- a/src/openai/cli/_progress.py +++ b/src/openai/cli/_progress.py @@ -1,48 +1,35 @@ from __future__ import annotations - import io from typing import Callable from typing_extensions import override - +import tqdm class CancelledError(Exception): def __init__(self, msg: str) -> None: - self.msg = msg super().__init__(msg) - @override - def __str__(self) -> str: - return self.msg - - __repr__ = __str__ - - class BufferReader(io.BytesIO): def __init__(self, buf: bytes = b"", desc: str | None = None) -> None: super().__init__(buf) - self._len = len(buf) self._progress = 0 self._callback = progress(len(buf), desc=desc) def __len__(self) -> int: - return self._len + return len(self.getvalue()) @override def read(self, n: int | None = -1) -> bytes: - chunk = io.BytesIO.read(self, n) + chunk = super().read(n) self._progress += len(chunk) try: self._callback(self._progress) - except Exception as e: # catches exception from the callback - raise CancelledError("The upload was cancelled: {}".format(e)) + except Exception as e: + raise CancelledError(f"The upload was cancelled: {e}") return chunk - def progress(total: float, desc: str | None) -> Callable[[float], None]: - import tqdm - meter = tqdm.tqdm(total=total, unit_scale=True, desc=desc) def incr(progress: float) -> None: @@ -54,6 +41,5 @@ def incr(progress: float) -> None: return incr - def MB(i: int) -> int: - return int(i // 1024**2) + return i // 1024**2