Fix some type issues in storage_client.py

This commit is contained in:
Itamar Turner-Trauring 2023-06-14 16:02:04 -04:00
parent 65775cd6bd
commit 11e0151838
3 changed files with 15 additions and 7 deletions

View File

@ -17,11 +17,13 @@ if PY2:
from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, pow, round, super, range, max, min # noqa: F401
from past.builtins import long
from typing import Dict
from zope.interface import Interface, Attribute
from twisted.plugin import (
IPlugin,
)
from twisted.internet.defer import Deferred
from foolscap.api import StringConstraint, ListOf, TupleOf, SetOf, DictOf, \
ChoiceOf, IntegerConstraint, Any, RemoteInterface, Referenceable
@ -307,12 +309,15 @@ class RIStorageServer(RemoteInterface):
store that on disk.
"""
# The result of IStorageServer.get_version():
VersionMessage = Dict[bytes, object]
class IStorageServer(Interface):
"""
An object capable of storing shares for a storage client.
"""
def get_version():
def get_version() -> Deferred[VersionMessage]:
"""
:see: ``RIStorageServer.get_version``
"""

View File

@ -57,6 +57,7 @@ from .http_common import (
CBOR_MIME_TYPE,
get_spki_hash,
)
from ..interfaces import VersionMessage
from .common import si_b2a, si_to_human_readable
from ..util.hashutil import timing_safe_compare
from ..util.deferredutil import async_to_deferred
@ -576,7 +577,7 @@ class StorageClientGeneral(object):
_client: StorageClient
@async_to_deferred
async def get_version(self) -> dict[bytes, object]:
async def get_version(self) -> VersionMessage:
"""
Return the version metadata for the server.
"""
@ -585,7 +586,7 @@ class StorageClientGeneral(object):
):
return await self._get_version()
async def _get_version(self) -> dict[bytes, object]:
async def _get_version(self) -> VersionMessage:
"""Implementation of get_version()."""
url = self._client.relative_url("/storage/v1/version")
response = await self._client.request("GET", url)

View File

@ -33,7 +33,7 @@ Ported to Python 3.
from __future__ import annotations
from six import ensure_text
from typing import Union, Callable, Any, Optional
from typing import Union, Callable, Any, Optional, cast
from os import urandom
import re
import time
@ -53,6 +53,7 @@ from twisted.python.failure import Failure
from twisted.web import http
from twisted.internet.task import LoopingCall
from twisted.internet import defer, reactor
from twisted.internet.interfaces import IReactorTime
from twisted.application import service
from twisted.plugin import (
getPlugins,
@ -70,6 +71,7 @@ from allmydata.interfaces import (
IServer,
IStorageServer,
IFoolscapStoragePlugin,
VersionMessage
)
from allmydata.grid_manager import (
create_grid_manager_verifier,
@ -1089,7 +1091,7 @@ class HTTPNativeStorageServer(service.MultiService):
self._connection_status = connection_status.ConnectionStatus.unstarted()
self._version = None
self._last_connect_time = None
self._connecting_deferred = None
self._connecting_deferred : Optional[defer.Deferred[object]]= None
def get_permutation_seed(self):
return self._permutation_seed
@ -1266,7 +1268,7 @@ class HTTPNativeStorageServer(service.MultiService):
# If we've gotten this far, we've found a working NURL.
storage_client = await self._storage_client_factory.create_storage_client(
nurl, reactor, None
nurl, cast(IReactorTime, reactor), None
)
self._istorage_server = _HTTPStorageServer.from_http_client(storage_client)
return self._istorage_server
@ -1507,7 +1509,7 @@ class _HTTPStorageServer(object):
"""
return _HTTPStorageServer(http_client=http_client)
def get_version(self):
def get_version(self) -> defer.Deferred[VersionMessage]:
return StorageClientGeneral(self._http_client).get_version()
@defer.inlineCallbacks