From: Denis Laxalde Date: Fri, 5 Nov 2021 12:18:56 +0000 (+0100) Subject: Declare tx_params using TypeDict values in connection tests X-Git-Tag: 3.0.3~3^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c714cdc5188500ac873be563efd6d71690dc1c3;p=thirdparty%2Fpsycopg.git Declare tx_params using TypeDict values in connection tests This resolves a bunch of mypy errors because the second-level values of tx_params are of heterogeneous types. --- diff --git a/tests/test_connection.py b/tests/test_connection.py index 57c98db2a..e64832f53 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -5,6 +5,12 @@ import pytest import logging import weakref from threading import Thread +from typing import Any, List + +if sys.version_info >= (3, 8): + from typing import TypedDict +else: + from typing_extensions import TypedDict import psycopg from psycopg import Connection, Notify @@ -526,22 +532,34 @@ def test_server_cursor_factory(conn): assert isinstance(cur, MyServerCursor) +class ParamDef(TypedDict): + guc: str + values: List[Any] + set_method: str + + tx_params = { - "isolation_level": { - "guc": "isolation", - "values": list(psycopg.IsolationLevel), - "set_method": "set_isolation_level", - }, - "read_only": { - "guc": "read_only", - "values": [True, False], - "set_method": "set_read_only", - }, - "deferrable": { - "guc": "deferrable", - "values": [True, False], - "set_method": "set_deferrable", - }, + "isolation_level": ParamDef( + { + "guc": "isolation", + "values": list(psycopg.IsolationLevel), + "set_method": "set_isolation_level", + } + ), + "read_only": ParamDef( + { + "guc": "read_only", + "values": [True, False], + "set_method": "set_read_only", + } + ), + "deferrable": ParamDef( + { + "guc": "deferrable", + "values": [True, False], + "set_method": "set_deferrable", + } + ), } # Map Python values to Postgres values for the tx_params possible values