Skip to content

Commit

Permalink
Fix the type-hints using more standard mode (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
ischaojie committed Dec 27, 2022
1 parent 6b0c767 commit 77d9b8a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion databases/backends/aiopg.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class AiopgConnection(ConnectionBackend):
def __init__(self, database: AiopgBackend, dialect: Dialect):
self._database = database
self._dialect = dialect
self._connection = None # type: typing.Optional[aiopg.Connection]
self._connection: typing.Optional[aiopg.Connection] = None

async def acquire(self) -> None:
assert self._connection is None, "Connection is already acquired"
Expand Down
2 changes: 1 addition & 1 deletion databases/backends/asyncmy.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class AsyncMyConnection(ConnectionBackend):
def __init__(self, database: AsyncMyBackend, dialect: Dialect):
self._database = database
self._dialect = dialect
self._connection = None # type: typing.Optional[asyncmy.Connection]
self._connection: typing.Optional[asyncmy.Connection] = None

async def acquire(self) -> None:
assert self._connection is None, "Connection is already acquired"
Expand Down
2 changes: 1 addition & 1 deletion databases/backends/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class MySQLConnection(ConnectionBackend):
def __init__(self, database: MySQLBackend, dialect: Dialect):
self._database = database
self._dialect = dialect
self._connection = None # type: typing.Optional[aiomysql.Connection]
self._connection: typing.Optional[aiomysql.Connection] = None

async def acquire(self) -> None:
assert self._connection is None, "Connection is already acquired"
Expand Down
8 changes: 3 additions & 5 deletions databases/backends/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _get_dialect(self) -> Dialect:
def _get_connection_kwargs(self) -> dict:
url_options = self._database_url.options

kwargs = {} # type: typing.Dict[str, typing.Any]
kwargs: typing.Dict[str, typing.Any] = {}
min_size = url_options.get("min_size")
max_size = url_options.get("max_size")
ssl = url_options.get("ssl")
Expand Down Expand Up @@ -162,7 +162,7 @@ class PostgresConnection(ConnectionBackend):
def __init__(self, database: PostgresBackend, dialect: Dialect):
self._database = database
self._dialect = dialect
self._connection = None # type: typing.Optional[asyncpg.connection.Connection]
self._connection: typing.Optional[asyncpg.connection.Connection] = None

async def acquire(self) -> None:
assert self._connection is None, "Connection is already acquired"
Expand Down Expand Up @@ -305,9 +305,7 @@ def raw_connection(self) -> asyncpg.connection.Connection:
class PostgresTransaction(TransactionBackend):
def __init__(self, connection: PostgresConnection):
self._connection = connection
self._transaction = (
None
) # type: typing.Optional[asyncpg.transaction.Transaction]
self._transaction: typing.Optional[asyncpg.transaction.Transaction] = None

async def start(
self, is_root: bool, extra_options: typing.Dict[typing.Any, typing.Any]
Expand Down
2 changes: 1 addition & 1 deletion databases/backends/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class SQLiteConnection(ConnectionBackend):
def __init__(self, pool: SQLitePool, dialect: Dialect):
self._pool = pool
self._dialect = dialect
self._connection = None # type: typing.Optional[aiosqlite.Connection]
self._connection: typing.Optional[aiosqlite.Connection] = None

async def acquire(self) -> None:
assert self._connection is None, "Connection is already acquired"
Expand Down
8 changes: 4 additions & 4 deletions databases/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ def __init__(
self._backend = backend_cls(self.url, **self.options)

# Connections are stored as task-local state.
self._connection_context = ContextVar("connection_context") # type: ContextVar
self._connection_context: ContextVar = ContextVar("connection_context")

# When `force_rollback=True` is used, we use a single global
# connection, within a transaction that always rolls back.
self._global_connection = None # type: typing.Optional[Connection]
self._global_transaction = None # type: typing.Optional[Transaction]
self._global_connection: typing.Optional[Connection] = None
self._global_transaction: typing.Optional[Transaction] = None

async def connect(self) -> None:
"""
Expand Down Expand Up @@ -223,7 +223,7 @@ def __init__(self, backend: DatabaseBackend) -> None:
self._connection_counter = 0

self._transaction_lock = asyncio.Lock()
self._transaction_stack = [] # type: typing.List[Transaction]
self._transaction_stack: typing.List[Transaction] = []

self._query_lock = asyncio.Lock()

Expand Down

0 comments on commit 77d9b8a

Please sign in to comment.