Skip to content

Commit

Permalink
Merge pull request #1351 from tahoe-lafs/4082-upgrade-mypy
Browse files Browse the repository at this point in the history
Upgrade to mypy 1.8
  • Loading branch information
itamarst committed Feb 21, 2024
2 parents 4fb973e + ed193c7 commit 40963cd
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
Empty file added newsfragments/4082.minor
Empty file.
21 changes: 12 additions & 9 deletions src/allmydata/storage_client.py
Expand Up @@ -32,7 +32,7 @@

from __future__ import annotations

from typing import Union, Callable, Any, Optional, cast, Dict
from typing import Union, Callable, Any, Optional, cast, Dict, Iterable
from os import urandom
import re
import time
Expand Down Expand Up @@ -139,9 +139,9 @@ class StorageClientConfig(object):
only upload to a storage-server that has a valid certificate
signed by at least one of these keys.
"""
preferred_peers = attr.ib(default=())
storage_plugins = attr.ib(default=attr.Factory(dict))
grid_manager_keys = attr.ib(default=attr.Factory(list))
preferred_peers : Iterable[bytes] = attr.ib(default=())
storage_plugins : dict[str, dict[str, str]] = attr.ib(default=attr.Factory(dict))
grid_manager_keys : list[ed25519.Ed25519PublicKey] = attr.ib(default=attr.Factory(list))

@classmethod
def from_node_config(cls, config):
Expand Down Expand Up @@ -1107,18 +1107,21 @@ def try_to_connect(self):
async def _pick_a_http_server(
reactor,
nurls: list[DecodedURL],
request: Callable[[Any, DecodedURL], defer.Deferred[Any]]
request: Callable[[object, DecodedURL], defer.Deferred[object]]
) -> DecodedURL:
"""Pick the first server we successfully send a request to.
Fires with ``None`` if no server was found, or with the ``DecodedURL`` of
the first successfully-connected server.
"""
queries = race([
request(reactor, nurl).addCallback(lambda _, nurl=nurl: nurl)
for nurl in nurls
])
requests = []
for nurl in nurls:
def to_nurl(_: object, nurl: DecodedURL=nurl) -> DecodedURL:
return nurl

requests.append(request(reactor, nurl).addCallback(to_nurl))

queries: defer.Deferred[tuple[int, DecodedURL]] = race(requests)
_, nurl = await queries
return nurl

Expand Down
6 changes: 3 additions & 3 deletions src/allmydata/test/common.py
Expand Up @@ -177,8 +177,8 @@ class MemoryIntroducerClient(object):
sequencer = attr.ib()
cache_filepath = attr.ib()

subscribed_to = attr.ib(default=attr.Factory(list))
published_announcements = attr.ib(default=attr.Factory(list))
subscribed_to : list[Subscription] = attr.ib(default=attr.Factory(list))
published_announcements : list[Announcement] = attr.ib(default=attr.Factory(list))


def setServiceParent(self, parent):
Expand Down Expand Up @@ -288,7 +288,7 @@ class UseNode(object):
basedir = attr.ib(validator=attr.validators.instance_of(FilePath))
introducer_furl = attr.ib(validator=attr.validators.instance_of(str),
converter=six.ensure_str)
node_config = attr.ib(default=attr.Factory(dict))
node_config : dict[bytes,bytes] = attr.ib(default=attr.Factory(dict))

config = attr.ib(default=None)
reactor = attr.ib(default=None)
Expand Down
3 changes: 2 additions & 1 deletion src/allmydata/test/test_storage_client.py
Expand Up @@ -41,6 +41,7 @@

from twisted.internet.interfaces import (
IStreamClientEndpoint,
IProtocolFactory,
)
from twisted.application.service import (
Service,
Expand Down Expand Up @@ -604,7 +605,7 @@ class SpyHandler(object):
``Deferred`` that was returned from ``connect`` and the factory that
was passed to ``connect``.
"""
_connects = attr.ib(default=attr.Factory(list))
_connects : list[tuple[Deferred[object], IProtocolFactory]]= attr.ib(default=attr.Factory(list))

def hint_to_endpoint(self, hint, reactor, update_status):
return (SpyEndpoint(self._connects.append), hint)
Expand Down
3 changes: 2 additions & 1 deletion src/allmydata/testing/web.py
Expand Up @@ -14,6 +14,7 @@
from __future__ import annotations

import hashlib
from typing import Iterable

import attr

Expand Down Expand Up @@ -141,7 +142,7 @@ class _FakeTahoeUriHandler(Resource, object):
isLeaf = True

data: BytesKeyDict = attr.ib(default=attr.Factory(BytesKeyDict))
capability_generators = attr.ib(default=attr.Factory(dict))
capability_generators: dict[bytes,Iterable[bytes]] = attr.ib(default=attr.Factory(dict))

def _generate_capability(self, kind):
"""
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -124,7 +124,7 @@ commands =
[testenv:typechecks]
basepython = python3
deps =
mypy==1.5.1
mypy==1.8.0
mypy-zope
types-mock
types-six
Expand Down

0 comments on commit 40963cd

Please sign in to comment.