# Drop "return: None" from the function signatures
if ann["return"] is None:
del ann["return"]
- elif ann["return"] == "PGcancel":
- ann["return"] = "psycopg3.pq.PGcancel"
def process_signature(
state so adapting several values of the same type can be optimised.
"""
+ __module__ = "psycopg3.adapt"
+
def __init__(self, context: AdaptContext = None):
self._dumpers: DumpersMap
self._loaders: LoadersMap
execute: Callable[["PGconn"], PQGen[List["PGresult"]]]
if TYPE_CHECKING:
- import psycopg3
+ from .cursor import AsyncCursor, Cursor
from .pq.proto import PGconn, PGresult
if pq.__impl__ == "c":
"""The PID of the backend process which sent the notification."""
+Notify.__module__ = "psycopg3"
+
NoticeHandler = Callable[[e.Diagnostic], None]
-NotifyHandler = Callable[["psycopg3.Notify"], None]
+NotifyHandler = Callable[[Notify], None]
class BaseConnection:
ConnStatus = pq.ConnStatus
TransactionStatus = pq.TransactionStatus
- cursor_factory: Union[
- Type["psycopg3.Cursor"], Type["psycopg3.AsyncCursor"]
- ]
+ cursor_factory: Union[Type["Cursor"], Type["AsyncCursor"]]
def __init__(self, pgconn: "PGconn"):
self.pgconn = pgconn # TODO: document this
Wrapper for a connection to the database.
"""
- cursor_factory: Type["psycopg3.Cursor"]
+ __module__ = "psycopg3"
+
+ cursor_factory: Type["Cursor"]
def __init__(self, pgconn: "PGconn"):
super().__init__(pgconn)
"""Close the database connection."""
self.pgconn.finish()
- def cursor(
- self, name: str = "", format: Format = Format.TEXT
- ) -> "psycopg3.Cursor":
+ def cursor(self, name: str = "", format: Format = Format.TEXT) -> "Cursor":
"""
Return a new `Cursor` to send commands and queries to the connection.
"""
result, encoding=self.client_encoding
)
- def notifies(self) -> Iterator["psycopg3.Notify"]:
+ def notifies(self) -> Iterator[Notify]:
"""
Yield `Notify` objects as soon as they are received from the database.
"""
Asynchronous wrapper for a connection to the database.
"""
- cursor_factory: Type["psycopg3.AsyncCursor"]
+ __module__ = "psycopg3"
+
+ cursor_factory: Type["AsyncCursor"]
def __init__(self, pgconn: "PGconn"):
super().__init__(pgconn)
async def cursor(
self, name: str = "", format: Format = Format.TEXT
- ) -> "psycopg3.AsyncCursor":
+ ) -> "AsyncCursor":
"""
Return a new `AsyncCursor` to send commands and queries to the connection.
"""
result, encoding=self.client_encoding
)
- async def notifies(self) -> AsyncIterator["psycopg3.Notify"]:
+ async def notifies(self) -> AsyncIterator[Notify]:
while 1:
async with self.lock:
ns = await self.wait(notifies(self.pgconn))
class Copy(BaseCopy["Connection"]):
"""Manage a :sql:`COPY` operation."""
+ __module__ = "psycopg3"
+
def read(self) -> bytes:
"""Read a row of data after a :sql:`COPY TO` operation.
class AsyncCopy(BaseCopy["AsyncConnection"]):
"""Manage an asynchronous :sql:`COPY` operation."""
+ __module__ = "psycopg3"
+
async def read(self) -> bytes:
if self._finished:
return b""
class Column(Sequence[Any]):
+
+ __module__ = "psycopg3"
+
def __init__(self, pgresult: "PGresult", index: int, encoding: str):
self._pgresult = pgresult
self._index = index
class Cursor(BaseCursor["Connection"]):
+ __module__ = "psycopg3"
+
def __enter__(self) -> "Cursor":
return self
class AsyncCursor(BaseCursor["AsyncConnection"]):
+ __module__ = "psycopg3"
+
async def __aenter__(self) -> "AsyncCursor":
return self
Python representation of a libpq connection.
"""
+ __module__ = "psycopg3.pq"
__slots__ = (
"pgconn_ptr",
"notice_handler",
Python representation of a libpq result.
"""
+ __module__ = "psycopg3.pq"
__slots__ = ("pgresult_ptr",)
def __init__(self, pgresult_ptr: impl.PGresult_struct):
Created by `PGconn.get_cancel()`.
"""
+ __module__ = "psycopg3.pq"
__slots__ = ("pgcancel_ptr",)
def __init__(self, pgcancel_ptr: impl.PGcancel_struct):
Utility object to manipulate connection strings.
"""
+ __module__ = "psycopg3.pq"
+
@classmethod
def get_defaults(cls) -> List[ConninfoOption]:
opts = impl.PQconndefaults()
Utility object to escape strings for SQL interpolation.
"""
+ __module__ = "psycopg3.pq"
+
def __init__(self, conn: Optional[PGconn] = None):
self.conn = conn
enclosing transactions contexts up to and including the one specified.
"""
+ __module__ = "psycopg3"
+
def __init__(
self,
transaction: Union["Transaction", "AsyncTransaction", None] = None,
Returned by `Connection.transaction()` to handle a transaction block.
"""
+ __module__ = "psycopg3"
+
def __enter__(self) -> "Transaction":
with self._conn.lock:
self._execute(self._enter_commands())
Returned by `AsyncConnection.transaction()` to handle a transaction block.
"""
+ __module__ = "psycopg3"
+
async def __aenter__(self) -> "AsyncTransaction":
async with self._conn.lock:
await self._execute(self._enter_commands())