diff --git a/CHANGES.md b/CHANGES.md index e9570915..fb13450d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,7 @@ ## Unreleased - +- datasets: Fix compatibility with Python 3.7 ## 2024/03/07 v0.0.7 - datasets: Fix dataset loader diff --git a/cratedb_toolkit/datasets/model.py b/cratedb_toolkit/datasets/model.py index e0ef6f2d..eec3e2c2 100644 --- a/cratedb_toolkit/datasets/model.py +++ b/cratedb_toolkit/datasets/model.py @@ -6,6 +6,11 @@ from cratedb_toolkit.util import DatabaseAdapter +try: + from typing import Literal +except ImportError: + from typing_extensions import Literal # type: ignore[assignment] + @dataclasses.dataclass class Dataset: @@ -68,7 +73,7 @@ def __post_init__(self): def create( self, - if_exists: t.Literal["append", "noop", "replace"] = "noop", + if_exists: Literal["append", "noop", "replace"] = "noop", drop: bool = False, ): """ @@ -95,7 +100,7 @@ def create( def load( self, - if_exists: t.Literal["append", "noop", "replace"] = "noop", + if_exists: Literal["append", "noop", "replace"] = "noop", drop: bool = False, ): self.create(if_exists=if_exists, drop=drop) diff --git a/cratedb_toolkit/util/database.py b/cratedb_toolkit/util/database.py index 1d286966..1e284009 100644 --- a/cratedb_toolkit/util/database.py +++ b/cratedb_toolkit/util/database.py @@ -13,6 +13,11 @@ from cratedb_toolkit.util.data import str_contains +try: + from typing import Literal +except ImportError: + from typing_extensions import Literal # type: ignore[assignment] + def run_sql(dburi: str, sql: str, records: bool = False): return DatabaseAdapter(dburi=dburi).run_sql(sql=sql, records=records) @@ -74,7 +79,7 @@ def run_sql_real(self, sql: str, records: bool = False): else: return results - def count_records(self, tablename_full: str, errors: t.Literal["raise", "ignore"] = "raise"): + def count_records(self, tablename_full: str, errors: Literal["raise", "ignore"] = "raise"): """ Return number of records in table. """ @@ -107,7 +112,7 @@ def refresh_table(self, tablename_full: str): self.run_sql(sql=sql) return True - def prune_table(self, tablename_full: str, errors: t.Literal["raise", "ignore"] = "raise"): + def prune_table(self, tablename_full: str, errors: Literal["raise", "ignore"] = "raise"): """ Run a `DELETE FROM ...` command. """ diff --git a/pyproject.toml b/pyproject.toml index c65da6aa..b62dc450 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -96,6 +96,7 @@ dependencies = [ "python-slugify<9", "sqlalchemy", "sqlparse<0.5", + 'typing-extensions<5; python_version <= "3.7"', ] [project.optional-dependencies] all = [