From 857a02f56e7af36b4f7d649205f4eb99526466d5 Mon Sep 17 00:00:00 2001 From: Chandrashekhar R <73425927+cr2007@users.noreply.github.com> Date: Tue, 4 Jun 2024 19:51:42 +0400 Subject: [PATCH] Update Python version in workflows and add typing features * Updated `pylint.yml` workflow file to use only Python versions 3.8+ * Added support for TypedDict and Literal types in `__init__.py` (Python 3.9+) * Fall back to using `typing_extensions` for older Python versions This commit ensures that our code is compatible with the latest Python versions while still supporting older versions. --- .github/workflows/pylint.yml | 2 +- cambai/__init__.py | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 1e5e3f0..df4de44 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.7", "3.8", "3.9", "3.10"] + python-version: ["3.8", "3.9", "3.10"] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} diff --git a/cambai/__init__.py b/cambai/__init__.py index ba80dcd..ad92586 100644 --- a/cambai/__init__.py +++ b/cambai/__init__.py @@ -3,19 +3,18 @@ import math import json from time import sleep -from typing import Optional +from typing import Optional, Literal, TypedDict from enum import IntEnum import requests from rich import print from tqdm import tqdm -if sys.version_info >= (3, 8): - # Python 3.8+ supports the built-in TypedDict and Literal types - from typing import Literal, TypedDict -else: - from typing_extensions import Literal, TypedDict +# Check the Python version at runtime +if sys.version_info < (3, 9): + # For Python versions less than 3.9, import Literal and TypedDict from typing_extensions from typing import List as list + class APIKeyMissingError(Exception): """Exception raised when the API Key is missing."""