From: Daniele Varrazzo Date: Mon, 27 Jun 2022 21:09:19 +0000 (+0100) Subject: refactor: restrict Query alias to use Composed or SQL instead of Composable X-Git-Tag: 3.1~53^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96172e55a26fe2b834658a5bebbba9c760296452;p=thirdparty%2Fpsycopg.git refactor: restrict Query alias to use Composed or SQL instead of Composable Other Composable subclasses (Identifier, Literal, Placeholder...) don't make sense as a complete query. --- diff --git a/psycopg/psycopg/abc.py b/psycopg/psycopg/abc.py index e6ff7607e..0da76e4d0 100644 --- a/psycopg/psycopg/abc.py +++ b/psycopg/psycopg/abc.py @@ -13,7 +13,7 @@ from ._enums import PyFormat as PyFormat from ._compat import Protocol, TypeAlias, LiteralString if TYPE_CHECKING: - from .sql import Composable + from . import sql from .rows import Row, RowMaker from .pq.abc import PGresult from .waiting import Wait, Ready @@ -23,7 +23,7 @@ if TYPE_CHECKING: # An object implementing the buffer protocol Buffer: TypeAlias = Union[bytes, bytearray, memoryview] -Query: TypeAlias = Union[LiteralString, bytes, "Composable"] +Query: TypeAlias = Union[LiteralString, bytes, "sql.SQL", "sql.Composed"] Params: TypeAlias = Union[Sequence[Any], Mapping[str, Any]] ConnectionType = TypeVar("ConnectionType", bound="BaseConnection[Any]") PipelineCommand: TypeAlias = Callable[[], None] diff --git a/psycopg/psycopg/server_cursor.py b/psycopg/psycopg/server_cursor.py index 564392639..0e77a6fdd 100644 --- a/psycopg/psycopg/server_cursor.py +++ b/psycopg/psycopg/server_cursor.py @@ -172,7 +172,7 @@ class ServerCursorMixin(BaseCursor[ConnectionType, Row]): ) yield from self._conn._exec_command(query) - def _make_declare_statement(self, query: Query) -> sql.Composable: + def _make_declare_statement(self, query: Query) -> sql.Composed: if isinstance(query, bytes): query = query.decode(self._encoding)