Skip to content

Commit

Permalink
datasets: Fix compatibility with Python 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Mar 11, 2024
1 parent 41ce991 commit bed97a0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


## Unreleased

- datasets: Fix compatibility with Python 3.7

## 2024/03/07 v0.0.7
- datasets: Fix dataset loader
Expand Down
9 changes: 7 additions & 2 deletions cratedb_toolkit/datasets/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
):
"""
Expand All @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions cratedb_toolkit/util/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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.
"""
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ dependencies = [
"python-slugify<9",
"sqlalchemy",
"sqlparse<0.5",
'typing-extensions<5; python_version <= "3.7"',
]
[project.optional-dependencies]
all = [
Expand Down

0 comments on commit bed97a0

Please sign in to comment.