Skip to content

Commit bed97a0

Browse files
committed
datasets: Fix compatibility with Python 3.7
1 parent 41ce991 commit bed97a0

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
## Unreleased
5-
5+
- datasets: Fix compatibility with Python 3.7
66

77
## 2024/03/07 v0.0.7
88
- datasets: Fix dataset loader

cratedb_toolkit/datasets/model.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
from cratedb_toolkit.util import DatabaseAdapter
88

9+
try:
10+
from typing import Literal
11+
except ImportError:
12+
from typing_extensions import Literal # type: ignore[assignment]
13+
914

1015
@dataclasses.dataclass
1116
class Dataset:
@@ -68,7 +73,7 @@ def __post_init__(self):
6873

6974
def create(
7075
self,
71-
if_exists: t.Literal["append", "noop", "replace"] = "noop",
76+
if_exists: Literal["append", "noop", "replace"] = "noop",
7277
drop: bool = False,
7378
):
7479
"""
@@ -95,7 +100,7 @@ def create(
95100

96101
def load(
97102
self,
98-
if_exists: t.Literal["append", "noop", "replace"] = "noop",
103+
if_exists: Literal["append", "noop", "replace"] = "noop",
99104
drop: bool = False,
100105
):
101106
self.create(if_exists=if_exists, drop=drop)

cratedb_toolkit/util/database.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313

1414
from cratedb_toolkit.util.data import str_contains
1515

16+
try:
17+
from typing import Literal
18+
except ImportError:
19+
from typing_extensions import Literal # type: ignore[assignment]
20+
1621

1722
def run_sql(dburi: str, sql: str, records: bool = False):
1823
return DatabaseAdapter(dburi=dburi).run_sql(sql=sql, records=records)
@@ -74,7 +79,7 @@ def run_sql_real(self, sql: str, records: bool = False):
7479
else:
7580
return results
7681

77-
def count_records(self, tablename_full: str, errors: t.Literal["raise", "ignore"] = "raise"):
82+
def count_records(self, tablename_full: str, errors: Literal["raise", "ignore"] = "raise"):
7883
"""
7984
Return number of records in table.
8085
"""
@@ -107,7 +112,7 @@ def refresh_table(self, tablename_full: str):
107112
self.run_sql(sql=sql)
108113
return True
109114

110-
def prune_table(self, tablename_full: str, errors: t.Literal["raise", "ignore"] = "raise"):
115+
def prune_table(self, tablename_full: str, errors: Literal["raise", "ignore"] = "raise"):
111116
"""
112117
Run a `DELETE FROM ...` command.
113118
"""

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ dependencies = [
9696
"python-slugify<9",
9797
"sqlalchemy",
9898
"sqlparse<0.5",
99+
'typing-extensions<5; python_version <= "3.7"',
99100
]
100101
[project.optional-dependencies]
101102
all = [

0 commit comments

Comments
 (0)