replace optional with union

This commit is contained in:
AF 2022-11-21 01:11:40 +00:00
parent 87ba808c2a
commit 3c67459bf1

View File

@ -6,7 +6,7 @@ import pathlib
import threading
import traceback
from io import StringIO, UnsupportedOperation
from typing import Any, Optional, IO, Hashable
from typing import Any, IO, Hashable
__all__ = (
@ -25,7 +25,7 @@ class Request:
'__future',
)
def __init__(self, future: Optional[asyncio.Future], /) -> None:
def __init__(self, future: asyncio.Future | None, /) -> None:
self.__future = future
def waiting(self, /) -> bool:
@ -49,7 +49,7 @@ class LineRequest(Request):
'line',
)
def __init__(self, line: str, /, *, future: Optional[asyncio.Future]) -> None:
def __init__(self, line: str, /, *, future: asyncio.Future | None) -> None:
super().__init__(future)
self.line = line
@ -76,7 +76,7 @@ note: unstable signature."""
key, value = self.fromline(line)
db[key] = value
def request(self, key: Any, value: Any, /, *, future: Optional[asyncio.Future]) -> 'KVRequest':
def request(self, key: Any, value: Any, /, *, future: asyncio.Future | None) -> 'KVRequest':
"""form request with Future.
low-level API.
note: unstable signature."""
@ -95,7 +95,7 @@ class KVRequest(LineRequest):
'value',
)
def __init__(self, key: Any, value: Any, /, *, future: Optional[asyncio.Future], factory: KVFactory):
def __init__(self, key: Any, value: Any, /, *, future: asyncio.Future | None, factory: KVFactory):
super().__init__(factory.line(key, value), future=future)
self.__factory = factory
self.key = key
@ -141,7 +141,7 @@ class TransactionRequest(LineRequest):
'buffer',
)
def __init__(self, buffer: StringIO, /, *, future: Optional[asyncio.Future]):
def __init__(self, buffer: StringIO, /, *, future: asyncio.Future | None):
super().__init__(buffer.getvalue(), future=future)
self.buffer = buffer
@ -393,13 +393,13 @@ note: unstable signature."""
self.__path_recover.unlink()
self.__path_backup.unlink()
def _copy_sync(self, db: Optional[dict], /) -> None:
def _copy_sync(self, db: dict | None, /) -> None:
if db is None:
db = {}
self._path2db_sync(self.__path_backup, db)
self._db2path_sync(db, self.__path)
def _finish_recovery_sync(self, db: Optional[dict], /) -> None:
def _finish_recovery_sync(self, db: dict | None, /) -> None:
self._copy_sync(db)
self._recovery_unset_sync()