from . import waiting
from .abc import AdaptContext, Params, PQGen, PQGenConn, Query, RV
from ._tpc import Xid
-from .rows import Row, RowFactory, tuple_row, TupleRow, args_row
+from .rows import Row, RowFactory, tuple_row, args_row
from .adapt import AdaptersMap
from ._enums import IsolationLevel
from ._compat import Self
cursor_factory: Optional[Type[Cursor[Row]]] = None,
context: Optional[AdaptContext] = None,
**kwargs: Union[None, int, str],
- ) -> Connection[Row]:
- # TODO: returned type should be Self. See #308.
- # Unfortunately we cannot use Self[Row] as Self is not parametric.
- # https://peps.python.org/pep-0673/#use-in-generic-classes
+ ) -> Self:
...
@overload
cursor_factory: Optional[Type[Cursor[Any]]] = None,
context: Optional[AdaptContext] = None,
**kwargs: Union[None, int, str],
- ) -> Connection[TupleRow]:
+ ) -> Self:
...
@classmethod # type: ignore[misc] # https://github.com/python/mypy/issues/11004
from . import waiting
from .abc import AdaptContext, Params, PQGen, PQGenConn, Query, RV
from ._tpc import Xid
-from .rows import Row, AsyncRowFactory, tuple_row, TupleRow, args_row
+from .rows import Row, AsyncRowFactory, tuple_row, args_row
from .adapt import AdaptersMap
from ._enums import IsolationLevel
from ._compat import Self
cursor_factory: Optional[Type[AsyncCursor[Row]]] = None,
context: Optional[AdaptContext] = None,
**kwargs: Union[None, int, str],
- ) -> AsyncConnection[Row]:
- # TODO: returned type should be Self. See #308.
- # Unfortunately we cannot use Self[Row] as Self is not parametric.
- # https://peps.python.org/pep-0673/#use-in-generic-classes
+ ) -> Self:
...
@overload
cursor_factory: Optional[Type[AsyncCursor[Any]]] = None,
context: Optional[AdaptContext] = None,
**kwargs: Union[None, int, str],
- ) -> AsyncConnection[TupleRow]:
+ ) -> Self:
...
@classmethod # type: ignore[misc] # https://github.com/python/mypy/issues/11004
# Copyright (C) 2022 The Psycopg Team
import re
-from typing import Any, Optional, Type, Union, overload, TYPE_CHECKING
+from typing import Any, Optional, Union, TYPE_CHECKING
from .. import errors as e
-from ..abc import AdaptContext
-from ..rows import Row, RowFactory, AsyncRowFactory, TupleRow
-from .._compat import Self
+from ..rows import Row
from ..conninfo import ConnectionInfo
from ..connection import Connection
from .._adapters_map import AdaptersMap
if TYPE_CHECKING:
from ..pq.abc import PGconn
- from ..cursor import Cursor
- from ..cursor_async import AsyncCursor
class _CrdbConnectionMixin:
__module__ = "psycopg.crdb"
- # TODO: this method shouldn't require re-definition if the base class
- # implements a generic self.
- # https://github.com/psycopg/psycopg/issues/308
- @overload
- @classmethod
- def connect(
- cls,
- conninfo: str = "",
- *,
- autocommit: bool = False,
- row_factory: RowFactory[Row],
- prepare_threshold: Optional[int] = 5,
- cursor_factory: "Optional[Type[Cursor[Row]]]" = None,
- context: Optional[AdaptContext] = None,
- **kwargs: Union[None, int, str],
- ) -> "CrdbConnection[Row]":
- ...
-
- @overload
- @classmethod
- def connect(
- cls,
- conninfo: str = "",
- *,
- autocommit: bool = False,
- prepare_threshold: Optional[int] = 5,
- cursor_factory: "Optional[Type[Cursor[Any]]]" = None,
- context: Optional[AdaptContext] = None,
- **kwargs: Union[None, int, str],
- ) -> "CrdbConnection[TupleRow]":
- ...
-
- @classmethod
- def connect(cls, conninfo: str = "", **kwargs: Any) -> Self:
- """
- Connect to a database server and return a new `CrdbConnection` instance.
- """
- return super().connect(conninfo, **kwargs) # type: ignore[return-value]
-
class AsyncCrdbConnection(_CrdbConnectionMixin, AsyncConnection[Row]):
"""
__module__ = "psycopg.crdb"
- # TODO: this method shouldn't require re-definition if the base class
- # implements a generic self.
- # https://github.com/psycopg/psycopg/issues/308
- @overload
- @classmethod
- async def connect(
- cls,
- conninfo: str = "",
- *,
- autocommit: bool = False,
- prepare_threshold: Optional[int] = 5,
- row_factory: AsyncRowFactory[Row],
- cursor_factory: "Optional[Type[AsyncCursor[Row]]]" = None,
- context: Optional[AdaptContext] = None,
- **kwargs: Union[None, int, str],
- ) -> "AsyncCrdbConnection[Row]":
- ...
-
- @overload
- @classmethod
- async def connect(
- cls,
- conninfo: str = "",
- *,
- autocommit: bool = False,
- prepare_threshold: Optional[int] = 5,
- cursor_factory: "Optional[Type[AsyncCursor[Any]]]" = None,
- context: Optional[AdaptContext] = None,
- **kwargs: Union[None, int, str],
- ) -> "AsyncCrdbConnection[TupleRow]":
- ...
-
- @classmethod
- async def connect(cls, conninfo: str = "", **kwargs: Any) -> Self:
- return await super().connect(conninfo, **kwargs) # type: ignore[no-any-return]
-
class CrdbConnectionInfo(ConnectionInfo):
"""