From b78f0c21bacd73fb1c7b588508146405fd08e169 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 15 Mar 2022 20:47:30 -0700 Subject: [PATCH] psycopg2: Accept Composable in place of query string (#7494) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.psycopg.org/docs/sql.html#psycopg2.sql.Composable “Composable objects can be passed directly to execute(), executemany(), copy_expert() in place of the query string.” Signed-off-by: Anders Kaseorg --- stubs/psycopg2/psycopg2/_psycopg.pyi | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/stubs/psycopg2/psycopg2/_psycopg.pyi b/stubs/psycopg2/psycopg2/_psycopg.pyi index b4983f65d..02c018b13 100644 --- a/stubs/psycopg2/psycopg2/_psycopg.pyi +++ b/stubs/psycopg2/psycopg2/_psycopg.pyi @@ -5,6 +5,7 @@ from typing import Any, TypeVar, overload import psycopg2 import psycopg2.extensions +from psycopg2.sql import Composable _Vars = Sequence[Any] | Mapping[str, Any] | None @@ -360,11 +361,11 @@ class cursor: def callproc(self, procname, parameters=...): ... def cast(self, oid, s): ... def close(self): ... - def copy_expert(self, sql, file, size=...): ... + def copy_expert(self, sql: str | bytes | Composable, file, size=...): ... def copy_from(self, file, table, sep=..., null=..., size=..., columns=...): ... def copy_to(self, file, table, sep=..., null=..., columns=...): ... - def execute(self, query: str | bytes, vars: _Vars = ...) -> None: ... - def executemany(self, query: str | bytes, vars_list: Iterable[_Vars]) -> None: ... + def execute(self, query: str | bytes | Composable, vars: _Vars = ...) -> None: ... + def executemany(self, query: str | bytes | Composable, vars_list: Iterable[_Vars]) -> None: ... def fetchall(self) -> list[tuple[Any, ...]]: ... def fetchmany(self, size=...) -> list[tuple[Any, ...]]: ... def fetchone(self) -> tuple[Any, ...] | Any: ...