Skip to content

Commit b2e3100

Browse files
NickCrewscpcloud
authored andcommitted
fix(typing): adjust a few small type errors
1 parent 9126733 commit b2e3100

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

ibis/backends/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ def compile(
13031303
expr: ir.Expr,
13041304
/,
13051305
*,
1306-
limit: str | int | None = None,
1306+
limit: int | None = None,
13071307
params: Mapping[ir.Expr, Any] | None = None,
13081308
**kwargs: Any,
13091309
) -> str | pl.LazyFrame:

ibis/backends/duckdb/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ def create_table(
274274

275275
return self.table(name, database=(catalog, database))
276276

277-
def table(self, name: str, /, *, database: str | None = None) -> ir.Table:
277+
def table(
278+
self, name: str, /, *, database: str | tuple[str, str] | None = None
279+
) -> ir.Table:
278280
table_loc = self._to_sqlglot_table(database)
279281

280282
# TODO: set these to better defaults

ibis/backends/sql/__init__.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def compile(
9595
expr: ir.Expr,
9696
/,
9797
*,
98-
limit: str | int | None = None,
98+
limit: int | None = None,
9999
params: Mapping[ir.Expr, Any] | None = None,
100100
pretty: bool = False,
101101
) -> str:
@@ -492,7 +492,7 @@ def _build_insert_template(
492492
schema: sch.Schema,
493493
catalog: str | None = None,
494494
columns: bool = False,
495-
placeholder: str | Iterable[str] = "?",
495+
placeholder: str = "?",
496496
) -> str:
497497
"""Builds an INSERT INTO table VALUES query string with placeholders.
498498
@@ -644,7 +644,9 @@ def _build_upsert_from_table(
644644
)
645645
return query
646646

647-
def truncate_table(self, name: str, /, *, database: str | None = None) -> None:
647+
def truncate_table(
648+
self, name: str, /, *, database: str | tuple[str, str] | None = None
649+
) -> None:
648650
"""Delete all rows from a table.
649651
650652
::: {.callout-note}
@@ -709,13 +711,13 @@ def _to_catalog_db_tuple(self, table_loc: sge.Table):
709711

710712
return sg_cat, sg_db
711713

712-
def _to_sqlglot_table(self, database):
714+
def _to_sqlglot_table(self, database: None | str | tuple[str, str]) -> sge.Table:
713715
quoted = self.compiler.quoted
714716
dialect = self.dialect
715717

716718
if database is None:
717719
# Create "table" with empty catalog and db
718-
database = sge.Table(catalog=None, db=None)
720+
sgt = sge.Table(catalog=None, db=None)
719721
elif isinstance(database, (list, tuple)):
720722
if len(database) > 2:
721723
raise ValueError(
@@ -734,7 +736,7 @@ def _to_sqlglot_table(self, database):
734736
'\n("catalog", "database")'
735737
'\n("database",)'
736738
)
737-
database = sge.Table(
739+
sgt = sge.Table(
738740
catalog=sg.to_identifier(catalog, quoted=quoted),
739741
db=sg.to_identifier(database, quoted=quoted),
740742
)
@@ -744,28 +746,28 @@ def _to_sqlglot_table(self, database):
744746
# sqlglot parsing of the string will assume that it's a Table
745747
# so we unpack the arguments into a new sqlglot object, switching
746748
# table (this) -> database (db) and database (db) -> catalog
747-
table = sg.parse_one(
749+
sgt = sg.parse_one(
748750
".".join(
749751
sg.to_identifier(part, quoted=quoted).sql(dialect)
750752
for part in database.split(".")
751753
),
752754
into=sge.Table,
753755
dialect=dialect,
754756
)
755-
if table.args["catalog"] is not None:
757+
if sgt.args["catalog"] is not None:
756758
raise exc.IbisInputError(
757-
f"Overspecified table hierarchy provided: `{table.sql(dialect)}`"
759+
f"Overspecified table hierarchy provided: `{sgt.sql(dialect)}`"
758760
)
759-
catalog = table.args["db"]
760-
db = table.args["this"]
761-
database = sge.Table(catalog=catalog, db=db)
761+
catalog = sgt.args["db"]
762+
db = sgt.args["this"]
763+
sgt = sge.Table(catalog=catalog, db=db)
762764
else:
763765
raise ValueError(
764766
"""Invalid database hierarchy format. Please use either dotted
765767
strings ('catalog.database') or tuples ('catalog', 'database')."""
766768
)
767769

768-
return database
770+
return sgt
769771

770772
def _register_builtin_udf(self, udf_node: ops.ScalarUDF) -> None:
771773
"""No-op."""

ibis/backends/sql/compilers/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ def to_sqlglot(
579579
self,
580580
expr: ir.Expr,
581581
*,
582-
limit: str | None = None,
582+
limit: Literal["default"] | int | None = None,
583583
params: Mapping[ir.Expr, Any] | None = None,
584584
):
585585
import ibis

0 commit comments

Comments
 (0)