From de97dd94cdad6f8aeb2c379974623ac68720ab5a Mon Sep 17 00:00:00 2001 From: Mitchel Cabuloy Date: Sun, 14 Aug 2022 18:13:29 +0800 Subject: [PATCH 1/3] Add pyright to pre-commit config --- .pre-commit-config.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a141268..5ddc4d3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,3 +11,11 @@ repos: rev: 22.6.0 hooks: - id: black + - repo: local + hooks: + - id: pyright + name: pyright + entry: poetry run npx pyright@1.1.266 + language: node + pass_filenames: false + types: [python] From e59285b5937a5393ff5c3e2a8c47654c266e80af Mon Sep 17 00:00:00 2001 From: Mitchel Cabuloy Date: Sun, 14 Aug 2022 18:16:03 +0800 Subject: [PATCH 2/3] Add pyright to tox --- tox.ini | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 21066c6..7202b48 100644 --- a/tox.ini +++ b/tox.ini @@ -4,6 +4,7 @@ envlist = flake8 black isort + pyright py37 py38 py39 @@ -14,7 +15,7 @@ python = 3.7: py37 3.8: py38 3.9: py39 - 3.10: py310, flake8, black, isort + 3.10: py310, flake8, black, isort, pyright [testenv] deps = psycopg2-binary @@ -29,6 +30,10 @@ commands = flake8 deps = black >=22.6.0, <23.0.0 commands = black --check ./ +[testenv:pyright] +deps = pyright == 1.1.266 +commands = pyright + [testenv:isort] deps = isort >= 5.10.1, <6.0.0 commands = isort dslr tests --check-only --diff From c908c883797b7790bba9a1d30ee12a88cc58c88b Mon Sep 17 00:00:00 2001 From: Mitchel Cabuloy Date: Sun, 14 Aug 2022 18:22:37 +0800 Subject: [PATCH 3/3] Fix pyright type issues --- dslr/operations.py | 3 +++ dslr/pg_client.py | 1 + dslr/runner.py | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dslr/operations.py b/dslr/operations.py index 59f572d..d2ee64b 100644 --- a/dslr/operations.py +++ b/dslr/operations.py @@ -81,6 +81,9 @@ def get_snapshots() -> List[Snapshot]: # Find the snapshot databases result = exec_sql("SELECT datname FROM pg_database WHERE datname LIKE 'dslr_%'") + if not result: + raise RuntimeError("Did not get results from database.") + snapshot_dbnames = sorted([row[0] for row in result]) # Parse the name into a Snapshot diff --git a/dslr/pg_client.py b/dslr/pg_client.py index dbc67c4..f26e819 100644 --- a/dslr/pg_client.py +++ b/dslr/pg_client.py @@ -1,6 +1,7 @@ from typing import Any, List, Optional, Tuple import psycopg2 +import psycopg2.extensions from dslr.console import console diff --git a/dslr/runner.py b/dslr/runner.py index cc48bb8..9cb96a4 100644 --- a/dslr/runner.py +++ b/dslr/runner.py @@ -54,7 +54,7 @@ def exec_shell(*cmd: str) -> Result: def exec_sql( - sql: Union[sql.SQL, str], data: Optional[List[Any]] = None + sql: Union[sql.Composed, str], data: Optional[List[Any]] = None ) -> Optional[List[Tuple[Any, ...]]]: """ Executes a SQL query.