From c4d0fc0dd66ec8a5aefd7a96c5ac9bf73000cdc2 Mon Sep 17 00:00:00 2001 From: Jeremy Lopez Date: Thu, 12 Dec 2024 12:55:10 -0500 Subject: [PATCH 1/2] Add py.typed to be able to run mypy with the package's hints. --- MANIFEST.in | 1 + spgci/py.typed | 0 2 files changed, 1 insertion(+) create mode 100644 MANIFEST.in create mode 100644 spgci/py.typed diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..5464672 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include spgci/py.typed diff --git a/spgci/py.typed b/spgci/py.typed new file mode 100644 index 0000000..e69de29 From 1ff7f7ed54f8a1c24b724dd972ada1ea598b9a67 Mon Sep 17 00:00:00 2001 From: Jeremy Lopez Date: Thu, 12 Dec 2024 13:40:14 -0500 Subject: [PATCH 2/2] Fix type hints for lru_cache. --- pyproject.toml | 4 ++-- spgci/auth.py | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7d965ab..57dd42a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "spgci" -version = "0.0.50" +version = "0.0.51" description = "SPGCI is an API Client for the S&P Commodity Insights REST API" authors = ["S&P Global Commodity Insights "] license = "Apache-2.0" @@ -34,4 +34,4 @@ build-backend = "poetry.core.masonry.api" [tool.pytest.ini_options] markers = [ "integtest", -] \ No newline at end of file +] diff --git a/spgci/auth.py b/spgci/auth.py index a7ea6a3..6659c29 100644 --- a/spgci/auth.py +++ b/spgci/auth.py @@ -12,13 +12,30 @@ # See the License for the specific language governing permissions and # limitations under the License. -from functools import lru_cache + import spgci.config as config import requests from requests.exceptions import HTTPError, SSLError import warnings from tenacity import retry, retry_if_exception_type, wait_fixed from spgci.exceptions import AuthError, PerSecondLimitError, DailyLimitError +from typing import TYPE_CHECKING + + +if TYPE_CHECKING: + from collections.abc import Callable + from typing import TypeVar + + + _CachedFn = TypeVar("_CachedFn", bound=Callable) + + def lru_cache() -> Callable[[_CachedFn], _CachedFn]: + """Ensure that the type hints still work after calling the lru_cache decorator.""" + pass + +else: + from functools import lru_cache + _throttle_retry = retry( retry=retry_if_exception_type(PerSecondLimitError), reraise=True, wait=wait_fixed(1)