Skip to content

Commit

Permalink
Update stubs for 0.28.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanforbes committed Jul 9, 2023
1 parent ce51175 commit 782ed09
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
12 changes: 12 additions & 0 deletions asyncpg-stubs/_testbase/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,15 @@ class ConnectedTestCase(ClusterTestCase):
server_version: Any = ...
def setUp(self) -> None: ...
def tearDown(self) -> None: ...

class HotStandbyTestCase(ClusterTestCase):
@classmethod
def setup_cluster(cls) -> None: ...
@classmethod
def get_cluster_connection_spec(cls, cluster: Any, kwargs: Any = ...) -> Any: ...
@classmethod
def get_connection_spec(cls, kwargs: Any = ...) -> Any: ...
@classmethod
def connect_primary(cls, **kwargs: Any) -> Any: ...
@classmethod
def connect_standby(cls, **kwargs: Any) -> Any: ...
19 changes: 17 additions & 2 deletions asyncpg-stubs/connect_utils.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from _typeshed import Self
from asyncio import AbstractEventLoop, Future, Protocol
from collections.abc import Awaitable, Callable
from enum import IntEnum
from enum import Enum, IntEnum
from ssl import SSLContext
from typing import NamedTuple
from typing import Any, NamedTuple
from typing_extensions import Final, Literal, TypeAlias

from . import connection

_ParsedSSLType: TypeAlias = SSLContext | Literal[False]
_PasswordType: TypeAlias = str | Callable[[], str] | Callable[[], Awaitable[str]]

Expand All @@ -30,6 +32,7 @@ class _ConnectionParameters(NamedTuple):
direct_tls: bool
connect_timeout: float
server_settings: dict[str, str] | None
target_session_attrs: SessionAttribute

class _ClientConfiguration(NamedTuple):
command_timeout: float | None
Expand All @@ -53,3 +56,15 @@ class TLSUpgradeProto(Protocol):
) -> None: ...
def data_received(self, data: bytes) -> None: ...
def connection_lost(self, exc: Exception | None) -> None: ...

class SessionAttribute(str, Enum):
any: str
primary: str
standby: str
prefer_standby: str
read_write: str
read_only: str

target_attrs_check: Final[
dict[SessionAttribute, Callable[[connection.Connection[Any]], Any]]
]
3 changes: 3 additions & 0 deletions asyncpg-stubs/connection.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ async def connect(
direct_tls: bool = ...,
record_class: type[_Record],
server_settings: dict[str, str] | None = ...,
target_session_attrs: connect_utils.SessionAttribute | None = ...,
) -> Connection[_Record]: ...
@overload
async def connect(
Expand All @@ -384,6 +385,7 @@ async def connect(
connection_class: type[_Connection],
record_class: type[_Record] = ...,
server_settings: dict[str, str] | None = ...,
target_session_attrs: connect_utils.SessionAttribute | None = ...,
) -> _Connection: ...
@overload
async def connect(
Expand All @@ -404,6 +406,7 @@ async def connect(
ssl: _SSLType | None = ...,
direct_tls: bool = ...,
server_settings: dict[str, str] | None = ...,
target_session_attrs: connect_utils.SessionAttribute | None = ...,
) -> Connection[protocol.Record]: ...

class _ConnectionProxy(Generic[_Record]):
Expand Down
2 changes: 2 additions & 0 deletions asyncpg-stubs/exceptions/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ __all__ = (
'OutdatedSchemaCacheError',
'ProtocolError',
'UnsupportedClientFeatureError',
'TargetServerAttributeNotMatched',
)

_PM = TypeVar('_PM', bound=PostgresMessage)
Expand Down Expand Up @@ -82,6 +83,7 @@ class InterfaceWarning(InterfaceMessage, UserWarning):

class InternalClientError(Exception): ...
class ProtocolError(InternalClientError): ...
class TargetServerAttributeNotMatched(InternalClientError): ...

class OutdatedSchemaCacheError(InternalClientError):
schema_name: str | None
Expand Down
1 change: 1 addition & 0 deletions asyncpg-stubs/pool.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ class Pool(Generic[_Record]):
record_class: type[_Record],
**connect_kwargs: object,
) -> None: ...
def is_closing(self) -> bool: ...
def get_size(self) -> int: ...
def get_min_size(self) -> int: ...
def get_max_size(self) -> int: ...
Expand Down
2 changes: 1 addition & 1 deletion asyncpg-stubs/transaction.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TransactionState(Enum):
FAILED: int

_IsolationLevels: TypeAlias = Literal[
'read_committed', 'serializable', 'repeatable_read'
'read_committed', 'read_uncommitted', 'serializable', 'repeatable_read'
]
ISOLATION_LEVELS: Final[set[_IsolationLevels]]
ISOLATION_LEVELS_BY_VALUE: Final[dict[str, _IsolationLevels]]
Expand Down

0 comments on commit 782ed09

Please sign in to comment.