mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
run mypy locally, bump mypy to 1.10.0, fix new errors
This commit is contained in:
@ -43,14 +43,14 @@ repos:
|
|||||||
- id: mdformat
|
- id: mdformat
|
||||||
additional_dependencies:
|
additional_dependencies:
|
||||||
- mdformat-gfm
|
- mdformat-gfm
|
||||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
- repo: local
|
||||||
rev: v1.5.1
|
|
||||||
hooks:
|
hooks:
|
||||||
- id: mypy
|
- id: mypy-local
|
||||||
additional_dependencies:
|
name: run mypy with all dev dependencies present
|
||||||
- mypy-protobuf
|
entry: python -m mypy -p libp2p
|
||||||
- trio-typing
|
language: system
|
||||||
exclude: 'tests/'
|
always_run: true
|
||||||
|
pass_filenames: false
|
||||||
- repo: local
|
- repo: local
|
||||||
hooks:
|
hooks:
|
||||||
- id: check-rst-files
|
- id: check-rst-files
|
||||||
|
|||||||
@ -69,7 +69,7 @@ class Ed25519PrivateKey(PrivateKey):
|
|||||||
def sign(self, data: bytes) -> bytes:
|
def sign(self, data: bytes) -> bytes:
|
||||||
h = SHA256.new(data)
|
h = SHA256.new(data)
|
||||||
signing_key = SigningKey(self.to_bytes())
|
signing_key = SigningKey(self.to_bytes())
|
||||||
return signing_key.sign(h)
|
return signing_key.sign(h.digest())
|
||||||
|
|
||||||
def get_public_key(self) -> PublicKey:
|
def get_public_key(self) -> PublicKey:
|
||||||
return Ed25519PublicKey(self.impl.public_key)
|
return Ed25519PublicKey(self.impl.public_key)
|
||||||
|
|||||||
@ -1,3 +1,7 @@
|
|||||||
|
from __future__ import (
|
||||||
|
annotations,
|
||||||
|
)
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import functools
|
import functools
|
||||||
import hashlib
|
import hashlib
|
||||||
@ -6,12 +10,8 @@ import time
|
|||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
Callable,
|
Callable,
|
||||||
Dict,
|
|
||||||
KeysView,
|
KeysView,
|
||||||
List,
|
|
||||||
NamedTuple,
|
NamedTuple,
|
||||||
Set,
|
|
||||||
Tuple,
|
|
||||||
cast,
|
cast,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -111,20 +111,20 @@ class TopicValidator(NamedTuple):
|
|||||||
class Pubsub(Service, IPubsub):
|
class Pubsub(Service, IPubsub):
|
||||||
host: IHost
|
host: IHost
|
||||||
|
|
||||||
router: "IPubsubRouter"
|
router: IPubsubRouter
|
||||||
|
|
||||||
peer_receive_channel: "trio.MemoryReceiveChannel[ID]"
|
peer_receive_channel: trio.MemoryReceiveChannel[ID]
|
||||||
dead_peer_receive_channel: "trio.MemoryReceiveChannel[ID]"
|
dead_peer_receive_channel: trio.MemoryReceiveChannel[ID]
|
||||||
|
|
||||||
seen_messages: LRU
|
seen_messages: LRU[bytes, int]
|
||||||
|
|
||||||
subscribed_topics_send: Dict[str, "trio.MemorySendChannel[rpc_pb2.Message]"]
|
subscribed_topics_send: dict[str, trio.MemorySendChannel[rpc_pb2.Message]]
|
||||||
subscribed_topics_receive: Dict[str, "TrioSubscriptionAPI"]
|
subscribed_topics_receive: dict[str, TrioSubscriptionAPI]
|
||||||
|
|
||||||
peer_topics: Dict[str, Set[ID]]
|
peer_topics: dict[str, set[ID]]
|
||||||
peers: Dict[ID, INetStream]
|
peers: dict[ID, INetStream]
|
||||||
|
|
||||||
topic_validators: Dict[str, TopicValidator]
|
topic_validators: dict[str, TopicValidator]
|
||||||
|
|
||||||
counter: int # uint64
|
counter: int # uint64
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ class Pubsub(Service, IPubsub):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
host: IHost,
|
host: IHost,
|
||||||
router: "IPubsubRouter",
|
router: IPubsubRouter,
|
||||||
cache_size: int = None,
|
cache_size: int = None,
|
||||||
strict_signing: bool = True,
|
strict_signing: bool = True,
|
||||||
msg_id_constructor: Callable[
|
msg_id_constructor: Callable[
|
||||||
@ -222,7 +222,7 @@ class Pubsub(Service, IPubsub):
|
|||||||
return self.host.get_id()
|
return self.host.get_id()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def protocols(self) -> Tuple[TProtocol, ...]:
|
def protocols(self) -> tuple[TProtocol, ...]:
|
||||||
return tuple(self.router.get_protocols())
|
return tuple(self.router.get_protocols())
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -311,7 +311,7 @@ class Pubsub(Service, IPubsub):
|
|||||||
"""
|
"""
|
||||||
self.topic_validators.pop(topic, None)
|
self.topic_validators.pop(topic, None)
|
||||||
|
|
||||||
def get_msg_validators(self, msg: rpc_pb2.Message) -> Tuple[TopicValidator, ...]:
|
def get_msg_validators(self, msg: rpc_pb2.Message) -> tuple[TopicValidator, ...]:
|
||||||
"""
|
"""
|
||||||
Get all validators corresponding to the topics in the message.
|
Get all validators corresponding to the topics in the message.
|
||||||
|
|
||||||
@ -569,8 +569,8 @@ class Pubsub(Service, IPubsub):
|
|||||||
:param msg_forwarder: the peer who forward us the message.
|
:param msg_forwarder: the peer who forward us the message.
|
||||||
:param msg: the message.
|
:param msg: the message.
|
||||||
"""
|
"""
|
||||||
sync_topic_validators: List[SyncValidatorFn] = []
|
sync_topic_validators: list[SyncValidatorFn] = []
|
||||||
async_topic_validators: List[AsyncValidatorFn] = []
|
async_topic_validators: list[AsyncValidatorFn] = []
|
||||||
for topic_validator in self.get_msg_validators(msg):
|
for topic_validator in self.get_msg_validators(msg):
|
||||||
if topic_validator.is_async:
|
if topic_validator.is_async:
|
||||||
async_topic_validators.append(
|
async_topic_validators.append(
|
||||||
|
|||||||
1
newsfragments/472.internal.rst
Normal file
1
newsfragments/472.internal.rst
Normal file
@ -0,0 +1 @@
|
|||||||
|
Bump to ``mypy==1.10.0``, run ``pre-commit`` local hook instead of ``mirrors-mypy``
|
||||||
22
setup.py
22
setup.py
@ -11,6 +11,7 @@ extras_require = {
|
|||||||
"build>=0.9.0",
|
"build>=0.9.0",
|
||||||
"bump-my-version>=0.5.3",
|
"bump-my-version>=0.5.3",
|
||||||
"ipython",
|
"ipython",
|
||||||
|
"mypy==1.10.0",
|
||||||
"pre-commit>=3.4.0",
|
"pre-commit>=3.4.0",
|
||||||
"tox>=4.0.0",
|
"tox>=4.0.0",
|
||||||
"twine",
|
"twine",
|
||||||
@ -52,19 +53,20 @@ with open("./README.md") as readme:
|
|||||||
|
|
||||||
|
|
||||||
install_requires = [
|
install_requires = [
|
||||||
"pycryptodome>=3.9.2",
|
|
||||||
"base58>=1.0.3",
|
"base58>=1.0.3",
|
||||||
"pymultihash>=0.8.2",
|
|
||||||
"multiaddr>=0.0.9",
|
|
||||||
"rpcudp>=3.0.0",
|
|
||||||
"lru-dict>=1.1.6",
|
|
||||||
"protobuf>=3.10.0",
|
|
||||||
"coincurve>=10.0.0",
|
"coincurve>=10.0.0",
|
||||||
"pynacl>=1.3.0",
|
|
||||||
"trio>=0.15.0",
|
|
||||||
"noiseprotocol>=0.3.0",
|
|
||||||
"trio-typing>=0.0.4",
|
|
||||||
"exceptiongroup>=1.2.0; python_version < '3.11'",
|
"exceptiongroup>=1.2.0; python_version < '3.11'",
|
||||||
|
"lru-dict>=1.1.6",
|
||||||
|
"multiaddr>=0.0.9",
|
||||||
|
"mypy-protobuf>=3.0.0",
|
||||||
|
"noiseprotocol>=0.3.0",
|
||||||
|
"protobuf>=3.10.0",
|
||||||
|
"pycryptodome>=3.9.2",
|
||||||
|
"pymultihash>=0.8.2",
|
||||||
|
"pynacl>=1.3.0",
|
||||||
|
"rpcudp>=3.0.0",
|
||||||
|
"trio-typing>=0.0.4",
|
||||||
|
"trio>=0.15.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
tox.ini
2
tox.ini
@ -34,6 +34,8 @@ allowlist_externals=make,pre-commit
|
|||||||
|
|
||||||
[testenv:py{38,39,310,311,312}-lint]
|
[testenv:py{38,39,310,311,312}-lint]
|
||||||
deps=pre-commit
|
deps=pre-commit
|
||||||
|
extras=
|
||||||
|
dev
|
||||||
commands=
|
commands=
|
||||||
pre-commit install
|
pre-commit install
|
||||||
pre-commit run --all-files --show-diff-on-failure
|
pre-commit run --all-files --show-diff-on-failure
|
||||||
|
|||||||
Reference in New Issue
Block a user