Skip to content

Commit

Permalink
Fixed typing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
egbertbouman committed Jan 17, 2024
1 parent a1b4173 commit d6bc9a9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
11 changes: 6 additions & 5 deletions ipv8/dht/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,12 +636,13 @@ async def find(self, target: bytes, force_nodes: bool, offset: int,
for routing_table in self.routing_tables.values():
crawl = Crawl(target, routing_table, force_nodes=force_nodes, offset=offset)
futures.append(self._find(crawl, debug=debug))
results: list[list[Node]] | \
list[list[DHTValue]] | \
list[tuple[list[DHTValue], Crawl]] = await gather(*futures)
results: list[list[Any] |
list[DHTValue] |
tuple[list[DHTValue], Crawl]] = await gather(*futures)

if debug:
results = cast(List[Tuple[List[Tuple[bytes, Optional[bytes]]], Crawl]], results)
return tuple(*[r[0] for r in results]), [r[1] for r in results]
results_debug = cast(List[Tuple[List[DHTValue], Crawl]], results)
return tuple(*[r[0] for r in results]), [r[1] for r in results_debug]
return tuple(*results)

async def find_values(self, target: bytes, offset: int = 0,
Expand Down
6 changes: 4 additions & 2 deletions ipv8/messaging/anonymization/hidden_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import random
import socket
import struct
from asyncio import CancelledError, gather, iscoroutine
from asyncio import gather, iscoroutine
from typing import TYPE_CHECKING, Any, Coroutine, Set, Tuple, cast

from ...bootstrapping.dispersy.bootstrapper import DispersyBootstrapper
Expand Down Expand Up @@ -171,7 +171,9 @@ async def estimate_swarm_size(self, info_hash: bytes, hops: int = 1, max_request
responses = await gather(*[swarm.lookup(ip) for ip in ips], return_exceptions=True)

# Collect responses
all_ += [result for result in responses if not isinstance(result, (CancelledError, Exception))]
for result in responses:
if result and not isinstance(result, (BaseException, Exception)):
all_.extend(result)
tried |= set(ips)

return len({ip.seeder_pk for ip in all_ if ip is not None and ip.source == PEER_SOURCE_PEX})
Expand Down
8 changes: 4 additions & 4 deletions ipv8/messaging/anonymization/tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import contextlib
import logging
import time
from asyncio import CancelledError, Future, gather
from asyncio import Future, gather
from binascii import hexlify
from dataclasses import dataclass
from typing import TYPE_CHECKING, Callable, Sequence, cast
Expand Down Expand Up @@ -427,9 +427,9 @@ def on_success(ips: list[IntroductionPoint]) -> list[IntroductionPoint]:
results = []
tasks = [self.lookup_func(self.info_hash, ip, self.hops) for ip in self.intro_points]
if tasks:
results = [result for result in (await gather(*tasks, return_exceptions=True))
if not isinstance(result, (CancelledError, Exception))]
results = sum(results, [])
for result in (await gather(*tasks, return_exceptions=True)):
if not isinstance(result, (BaseException, Exception)):
results.extend(result)
return on_success(results)
self.logger.info("Skipping lookup for swarm %s", hexlify(self.info_hash))
return None
Expand Down

0 comments on commit d6bc9a9

Please sign in to comment.