mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
turn mypy checks back on, fix some errors
This commit is contained in:
@ -43,13 +43,14 @@ repos:
|
|||||||
- id: mdformat
|
- id: mdformat
|
||||||
additional_dependencies:
|
additional_dependencies:
|
||||||
- mdformat-gfm
|
- mdformat-gfm
|
||||||
# - repo: https://github.com/pre-commit/mirrors-mypy
|
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||||
# rev: v1.5.1
|
rev: v1.5.1
|
||||||
# hooks:
|
hooks:
|
||||||
# - id: mypy
|
- id: mypy
|
||||||
# additional_dependencies:
|
additional_dependencies:
|
||||||
# - mypy-protobuf
|
- mypy-protobuf
|
||||||
# exclude: 'tests/|tests_interop/|crypto/|identity/|pubsub/|insecure/|noise/|security/'
|
# exclude: 'tests/|crypto/|identity/|pubsub/|insecure/|noise/|security/'
|
||||||
|
exclude: 'tests/'
|
||||||
- repo: local
|
- repo: local
|
||||||
hooks:
|
hooks:
|
||||||
- id: check-rst-files
|
- id: check-rst-files
|
||||||
|
|||||||
@ -56,7 +56,8 @@ class PublicKey(Key):
|
|||||||
"""Return the protobuf representation of this ``Key``."""
|
"""Return the protobuf representation of this ``Key``."""
|
||||||
key_type = self.get_type().value
|
key_type = self.get_type().value
|
||||||
data = self.to_bytes()
|
data = self.to_bytes()
|
||||||
protobuf_key = protobuf.PublicKey(key_type=key_type, data=data)
|
# type ignored - TODO add ECD_P256 to KeyType
|
||||||
|
protobuf_key = protobuf.PublicKey(key_type=key_type, data=data) # type: ignore
|
||||||
return protobuf_key
|
return protobuf_key
|
||||||
|
|
||||||
def serialize(self) -> bytes:
|
def serialize(self) -> bytes:
|
||||||
@ -83,7 +84,8 @@ class PrivateKey(Key):
|
|||||||
"""Return the protobuf representation of this ``Key``."""
|
"""Return the protobuf representation of this ``Key``."""
|
||||||
key_type = self.get_type().value
|
key_type = self.get_type().value
|
||||||
data = self.to_bytes()
|
data = self.to_bytes()
|
||||||
protobuf_key = protobuf.PrivateKey(key_type=key_type, data=data)
|
# type ignored - TODO add ECD_P256 to KeyType
|
||||||
|
protobuf_key = protobuf.PrivateKey(key_type=key_type, data=data) # type: ignore
|
||||||
return protobuf_key
|
return protobuf_key
|
||||||
|
|
||||||
def serialize(self) -> bytes:
|
def serialize(self) -> bytes:
|
||||||
|
|||||||
@ -145,7 +145,8 @@ class BasicHost(IHost):
|
|||||||
addrs.append(addr.encapsulate(p2p_part))
|
addrs.append(addr.encapsulate(p2p_part))
|
||||||
return addrs
|
return addrs
|
||||||
|
|
||||||
@asynccontextmanager
|
# type ignored because asynccontextmanager decorator is untyped
|
||||||
|
@asynccontextmanager # type: ignore
|
||||||
async def run(
|
async def run(
|
||||||
self, listen_addrs: Sequence[multiaddr.Multiaddr]
|
self, listen_addrs: Sequence[multiaddr.Multiaddr]
|
||||||
) -> AsyncIterator[None]:
|
) -> AsyncIterator[None]:
|
||||||
|
|||||||
@ -8,6 +8,9 @@ NOTE: currently missing the capability to indicate lengths by "varint" method.
|
|||||||
from abc import (
|
from abc import (
|
||||||
abstractmethod,
|
abstractmethod,
|
||||||
)
|
)
|
||||||
|
from typing import (
|
||||||
|
Literal,
|
||||||
|
)
|
||||||
|
|
||||||
from libp2p.io.abc import (
|
from libp2p.io.abc import (
|
||||||
MsgReadWriteCloser,
|
MsgReadWriteCloser,
|
||||||
@ -26,7 +29,7 @@ from .exceptions import (
|
|||||||
MessageTooLarge,
|
MessageTooLarge,
|
||||||
)
|
)
|
||||||
|
|
||||||
BYTE_ORDER = "big"
|
BYTE_ORDER: Literal["big", "little"] = "big"
|
||||||
|
|
||||||
|
|
||||||
async def read_length(reader: Reader, size_len_bytes: int) -> int:
|
async def read_length(reader: Reader, size_len_bytes: int) -> int:
|
||||||
|
|||||||
@ -83,9 +83,7 @@ class SwarmConn(INetConn):
|
|||||||
async def _handle_muxed_stream(self, muxed_stream: IMuxedStream) -> None:
|
async def _handle_muxed_stream(self, muxed_stream: IMuxedStream) -> None:
|
||||||
net_stream = await self._add_stream(muxed_stream)
|
net_stream = await self._add_stream(muxed_stream)
|
||||||
try:
|
try:
|
||||||
# Ignore type here since mypy complains:
|
await self.swarm.common_stream_handler(net_stream)
|
||||||
# https://github.com/python/mypy/issues/2427
|
|
||||||
await self.swarm.common_stream_handler(net_stream) # type: ignore
|
|
||||||
finally:
|
finally:
|
||||||
# As long as `common_stream_handler`, remove the stream.
|
# As long as `common_stream_handler`, remove the stream.
|
||||||
self.remove_stream(net_stream)
|
self.remove_stream(net_stream)
|
||||||
|
|||||||
@ -113,9 +113,7 @@ class Swarm(Service, INetworkService):
|
|||||||
# Create Notifee array
|
# Create Notifee array
|
||||||
self.notifees = []
|
self.notifees = []
|
||||||
|
|
||||||
# Ignore type here since mypy complains:
|
self.common_stream_handler = create_default_stream_handler(self)
|
||||||
# https://github.com/python/mypy/issues/2427
|
|
||||||
self.common_stream_handler = create_default_stream_handler(self) # type: ignore
|
|
||||||
|
|
||||||
self.listener_nursery = None
|
self.listener_nursery = None
|
||||||
self.event_listener_nursery_created = trio.Event()
|
self.event_listener_nursery_created = trio.Event()
|
||||||
@ -137,9 +135,7 @@ class Swarm(Service, INetworkService):
|
|||||||
return self.self_id
|
return self.self_id
|
||||||
|
|
||||||
def set_stream_handler(self, stream_handler: StreamHandlerFn) -> None:
|
def set_stream_handler(self, stream_handler: StreamHandlerFn) -> None:
|
||||||
# Ignore type here since mypy complains:
|
self.common_stream_handler = stream_handler
|
||||||
# https://github.com/python/mypy/issues/2427
|
|
||||||
self.common_stream_handler = stream_handler # type: ignore
|
|
||||||
|
|
||||||
async def dial_peer(self, peer_id: ID) -> INetConn:
|
async def dial_peer(self, peer_id: ID) -> INetConn:
|
||||||
"""
|
"""
|
||||||
@ -273,7 +269,7 @@ class Swarm(Service, INetworkService):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
async def conn_handler(
|
async def conn_handler(
|
||||||
read_write_closer: ReadWriteCloser, maddr=maddr
|
read_write_closer: ReadWriteCloser, maddr: Multiaddr = maddr
|
||||||
) -> None:
|
) -> None:
|
||||||
raw_conn = RawConnection(read_write_closer, False)
|
raw_conn = RawConnection(read_write_closer, False)
|
||||||
|
|
||||||
|
|||||||
@ -44,12 +44,10 @@ class TrioSubscriptionAPI(BaseSubscriptionAPI):
|
|||||||
unsubscribe_fn: UnsubscribeFn,
|
unsubscribe_fn: UnsubscribeFn,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.receive_channel = receive_channel
|
self.receive_channel = receive_channel
|
||||||
# Ignore type here since mypy complains: https://github.com/python/mypy/issues/2427 # noqa: E501
|
self.unsubscribe_fn = unsubscribe_fn
|
||||||
self.unsubscribe_fn = unsubscribe_fn # type: ignore
|
|
||||||
|
|
||||||
async def unsubscribe(self) -> None:
|
async def unsubscribe(self) -> None:
|
||||||
# Ignore type here since mypy complains: https://github.com/python/mypy/issues/2427 # noqa: E501
|
await self.unsubscribe_fn()
|
||||||
await self.unsubscribe_fn() # type: ignore
|
|
||||||
|
|
||||||
def __aiter__(self) -> AsyncIterator[rpc_pb2.Message]:
|
def __aiter__(self) -> AsyncIterator[rpc_pb2.Message]:
|
||||||
return self.receive_channel.__aiter__()
|
return self.receive_channel.__aiter__()
|
||||||
|
|||||||
@ -182,7 +182,9 @@ class InsecureTransport(BaseSecureTransport):
|
|||||||
|
|
||||||
def make_exchange_message(pubkey: PublicKey) -> plaintext_pb2.Exchange:
|
def make_exchange_message(pubkey: PublicKey) -> plaintext_pb2.Exchange:
|
||||||
pubkey_pb = crypto_pb2.PublicKey(
|
pubkey_pb = crypto_pb2.PublicKey(
|
||||||
key_type=pubkey.get_type().value, data=pubkey.to_bytes()
|
# type ignored - TODO add ECD_P256 to KeyType
|
||||||
|
key_type=pubkey.get_type().value, # type: ignore
|
||||||
|
data=pubkey.to_bytes(),
|
||||||
)
|
)
|
||||||
id_bytes = ID.from_pubkey(pubkey).to_bytes()
|
id_bytes = ID.from_pubkey(pubkey).to_bytes()
|
||||||
return plaintext_pb2.Exchange(id=id_bytes, pubkey=pubkey_pb)
|
return plaintext_pb2.Exchange(id=id_bytes, pubkey=pubkey_pb)
|
||||||
|
|||||||
@ -189,7 +189,8 @@ class Mplex(IMuxedConn):
|
|||||||
|
|
||||||
_bytes = header + encode_varint_prefixed(data)
|
_bytes = header + encode_varint_prefixed(data)
|
||||||
|
|
||||||
return await self.write_to_stream(_bytes)
|
# type ignored TODO figure out return for this and write_to_stream
|
||||||
|
return await self.write_to_stream(_bytes) # type: ignore
|
||||||
|
|
||||||
async def write_to_stream(self, _bytes: bytes) -> None:
|
async def write_to_stream(self, _bytes: bytes) -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -56,8 +56,7 @@ class BaseInteractiveProcess(AbstractInterativeProcess):
|
|||||||
async def start(self) -> None:
|
async def start(self) -> None:
|
||||||
if self.proc is not None:
|
if self.proc is not None:
|
||||||
return
|
return
|
||||||
# NOTE: Ignore type checks here since mypy complains about bufsize=0
|
self.proc = await trio.open_process(
|
||||||
self.proc = await trio.open_process( # type: ignore
|
|
||||||
[self.cmd] + self.args,
|
[self.cmd] + self.args,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT, # Redirect stderr to stdout, which makes parsing easier # noqa: E501
|
stderr=subprocess.STDOUT, # Redirect stderr to stdout, which makes parsing easier # noqa: E501
|
||||||
|
|||||||
@ -5,10 +5,13 @@ import subprocess
|
|||||||
from tempfile import (
|
from tempfile import (
|
||||||
TemporaryDirectory,
|
TemporaryDirectory,
|
||||||
)
|
)
|
||||||
|
from typing import (
|
||||||
|
Tuple,
|
||||||
|
)
|
||||||
import venv
|
import venv
|
||||||
|
|
||||||
|
|
||||||
def create_venv(parent_path):
|
def create_venv(parent_path: Path) -> Path:
|
||||||
venv_path = parent_path / "package-smoke-test"
|
venv_path = parent_path / "package-smoke-test"
|
||||||
venv.create(venv_path, with_pip=True)
|
venv.create(venv_path, with_pip=True)
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
@ -17,7 +20,7 @@ def create_venv(parent_path):
|
|||||||
return venv_path
|
return venv_path
|
||||||
|
|
||||||
|
|
||||||
def find_wheel(project_path):
|
def find_wheel(project_path: Path) -> Path:
|
||||||
wheels = list(project_path.glob("dist/*.whl"))
|
wheels = list(project_path.glob("dist/*.whl"))
|
||||||
|
|
||||||
if len(wheels) != 1:
|
if len(wheels) != 1:
|
||||||
@ -29,7 +32,9 @@ def find_wheel(project_path):
|
|||||||
return wheels[0]
|
return wheels[0]
|
||||||
|
|
||||||
|
|
||||||
def install_wheel(venv_path, wheel_path, extras=()):
|
def install_wheel(
|
||||||
|
venv_path: Path, wheel_path: Path, extras: Tuple[str, ...] = ()
|
||||||
|
) -> None:
|
||||||
if extras:
|
if extras:
|
||||||
extra_suffix = f"[{','.join(extras)}]"
|
extra_suffix = f"[{','.join(extras)}]"
|
||||||
else:
|
else:
|
||||||
@ -41,7 +46,7 @@ def install_wheel(venv_path, wheel_path, extras=()):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_install_local_wheel():
|
def test_install_local_wheel() -> None:
|
||||||
with TemporaryDirectory() as tmpdir:
|
with TemporaryDirectory() as tmpdir:
|
||||||
venv_path = create_venv(Path(tmpdir))
|
venv_path = create_venv(Path(tmpdir))
|
||||||
wheel_path = find_wheel(Path("."))
|
wheel_path = find_wheel(Path("."))
|
||||||
|
|||||||
Reference in New Issue
Block a user