Skip to content
Snippets Groups Projects
Commit 83fb36b8 authored by vlorentz's avatar vlorentz
Browse files

db_utils: Fix typing of db/conninfo objects

swh_set_db_module() takes a db_or_conninfo object, and passes it to execute_sqlfiles,
which only expects a conninfo.

This is detected by mypy when using a recent version of types-psycopg2.
parent d5897350
No related branches found
No related tags found
No related merge requests found
......@@ -35,9 +35,6 @@ ignore_missing_imports = True
[mypy-pkg_resources.*]
ignore_missing_imports = True
[mypy-psycopg2.*]
ignore_missing_imports = True
[mypy-pytest.*]
ignore_missing_imports = True
......
......@@ -5,6 +5,7 @@ pytz
requests-mock
types-click
types-flask
types-psycopg2
types-pytz
types-pyyaml
types-requests
......
......@@ -625,15 +625,22 @@ def create_database_for_package(
def execute_sqlfiles(
sqlfiles: Collection[pathlib.Path], conninfo: str, flavor: Optional[str] = None
sqlfiles: Collection[pathlib.Path],
db_or_conninfo: Union[str, pgconnection],
flavor: Optional[str] = None,
):
"""Execute a list of SQL files on the database pointed at with ``conninfo``.
"""Execute a list of SQL files on the database pointed at with ``db_or_conninfo``.
Args:
sqlfiles: List of SQL files to execute
conninfo: connection info string for the SQL database
db_or_conninfo: A database connection, or a database connection info string
flavor: the database flavor to initialize
"""
if isinstance(db_or_conninfo, str):
conninfo = db_or_conninfo
else:
conninfo = db_or_conninfo.dsn
psql_command = [
"psql",
"--quiet",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment