Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 7cf1719

Browse files
author
David Robertson
committed
Stub out the DB2API module
1 parent c8f1458 commit 7cf1719

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

synapse/storage/engines/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from enum import IntEnum
1616
from typing import Generic, Optional, TypeVar
1717

18-
from synapse.storage.types import Connection
18+
from synapse.storage.types import Connection, DBAPI2Module
1919

2020

2121
class IsolationLevel(IntEnum):
@@ -32,7 +32,7 @@ class IncorrectDatabaseSetup(RuntimeError):
3232

3333

3434
class BaseDatabaseEngine(Generic[ConnectionType], metaclass=abc.ABCMeta):
35-
def __init__(self, module):
35+
def __init__(self, module: DBAPI2Module):
3636
self.module = module
3737

3838
@property

synapse/storage/types.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,23 @@ def __exit__(
9494
traceback: Optional[TracebackType],
9595
) -> Optional[bool]:
9696
...
97+
98+
99+
class DBAPI2Module(Protocol):
100+
"""The module-level attributes that we use from PEP 249.
101+
102+
This is NOT a comprehensive stub for the entire DBAPI2."""
103+
104+
__name__: str
105+
106+
Warning: Type[Exception]
107+
Error: Type[Exception]
108+
DatabaseError: Type[Exception]
109+
OperationalError: Type[Exception]
110+
IntegrityError: Type[Exception]
111+
112+
def connect(self, **parameters: object) -> Connection:
113+
...
114+
115+
116+
__all__ = ["Cursor", "Connection", "DBAPI2Module"]

0 commit comments

Comments
 (0)