Skip to content

Commit 043d96f

Browse files
committed
Fix broken table_exists_at (Image.get_table doesn't return Nones any more) and add mypy + config.
1 parent 8f14dd7 commit 043d96f

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ docs/_build/
1212
dist/
1313
.venv/
1414
.cache/
15+
.mypy_cache/
1516

1617
.idea/
1718
pip-wheel-metadata

mypy.ini

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[mypy]
2+
python_version = 3.6
3+
warn_return_any = True
4+
warn_unused_configs = True
5+
6+
# Ignore no stubs for modules like psycopg2 etc
7+
ignore_missing_imports = True
8+
9+
# Allow reusing the same variable with multiple assignments of different types.
10+
allow_redefinition = True

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pylint = "^2.4"
3838
black = { version = "*", allows-prereleases = true }
3939
pre-commit = "^1.18"
4040
httpretty = "^0.9.6"
41+
mypy = "^0.720"
4142

4243
[tool.poetry.extras]
4344
ingestion = ["pandas", "sqlalchemy"]

splitgraph/core/repository.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from splitgraph.core.image_manager import ImageManager
2222
from splitgraph.core.sql import validate_import_sql
2323
from splitgraph.engine.postgres.engine import PostgresEngine
24-
from splitgraph.exceptions import CheckoutError, EngineInitializationError
24+
from splitgraph.exceptions import CheckoutError, EngineInitializationError, TableNotFoundError
2525
from ._common import (
2626
manage_audit_triggers,
2727
set_head,
@@ -1013,11 +1013,14 @@ def table_exists_at(
10131013
) -> bool:
10141014
"""Determines whether a given table exists in a Splitgraph image without checking it out. If `image_hash` is None,
10151015
determines whether the table exists in the current staging area."""
1016-
return (
1016+
if image is None:
10171017
repository.object_engine.table_exists(repository.to_schema(), table_name)
1018-
if image is None
1019-
else bool(image.get_table(table_name))
1020-
)
1018+
else:
1019+
try:
1020+
image.get_table(table_name)
1021+
return True
1022+
except TableNotFoundError:
1023+
return False
10211024

10221025

10231026
def _sync(

0 commit comments

Comments
 (0)