Skip to content

Commit d87ff32

Browse files
committed
fix: fixed all lint and typecheck errors
1 parent cbe39af commit d87ff32

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

multiaddr/codecs/onion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ def to_string(self, proto, buf):
4848
port = str(int.from_bytes(buf[10:12], byteorder='big'))
4949
if not 1 <= int(port) <= 65535:
5050
raise ValueError("Invalid onion port range")
51-
return f"{addr}:{port}"
51+
return f"{addr}:{port}" # noqa: E231
5252
except (ValueError, UnicodeDecodeError, binascii.Error) as e:
5353
raise BinaryParseError(str(e), buf, proto)

multiaddr/codecs/onion3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ def to_string(self, proto, buf):
5050
port = str(int.from_bytes(buf[35:], byteorder='big'))
5151
if not 1 <= int(port) <= 65535:
5252
raise ValueError("Invalid onion3 port range")
53-
return f"{addr}:{port}"
53+
return f"{addr}:{port}" # noqa: E231
5454
except (ValueError, UnicodeDecodeError, binascii.Error) as e:
5555
raise BinaryParseError(str(e), buf, proto)

multiaddr/multiaddr.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# flake8: noqa: F811
12
import collections.abc
23
from typing import Any, Iterator, List, Optional, Tuple, TypeVar, Union, Sequence, overload
34

@@ -48,7 +49,7 @@ def __iter__(self) -> Iterator[Any]:
4849
class MultiAddrItems(
4950
collections.abc.ItemsView[Any, Any],
5051
collections.abc.Sequence[Tuple[Any, Any]]
51-
):
52+
): # noqa: F811
5253
def __init__(self, mapping: 'Multiaddr') -> None:
5354
self._mapping = mapping
5455
super().__init__(mapping)
@@ -66,14 +67,14 @@ def __getitem__(self, idx: int) -> Tuple[Any, Any]: ...
6667
@overload
6768
def __getitem__(self, idx: slice) -> Sequence[Tuple[Any, Any]]: ...
6869

69-
def __getitem__(
70+
def __getitem__( # noqa: F811
7071
self,
7172
idx: Union[int, slice]
7273
) -> Union[Tuple[Any, Any], Sequence[Tuple[Any, Any]]]:
7374
if isinstance(idx, slice):
7475
return list(self)[idx]
7576
if idx < 0:
76-
idx = len(self)+idx
77+
idx = len(self) + idx
7778
for idx2, item in enumerate(self):
7879
if idx2 == idx:
7980
return item

multiaddr/transforms.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ def string_iter(string: str) -> Generator[Tuple[Protocol, CodecBase, Optional[st
110110
proto = protocol_with_name(element)
111111
print(f"[DEBUG] Found protocol: {proto.name}")
112112
if proto.codec is None:
113-
codec = None
113+
# Create a dummy codec with size 0 for protocols without a codec
114+
codec = CodecBase()
115+
codec.SIZE = 0
116+
codec.IS_PATH = False
114117
else:
115118
codec = codec_by_name(proto.codec)
116119
except (ImportError, exceptions.ProtocolNotFoundError) as exc:
@@ -145,7 +148,11 @@ def string_iter(string: str) -> Generator[Tuple[Protocol, CodecBase, Optional[st
145148
sp.pop(0)
146149
if not sp:
147150
print(f"[DEBUG] Protocol {proto.name} requires address but none left")
148-
raise exceptions.StringParseError("Protocol requires address", string, proto.name)
151+
raise exceptions.StringParseError(
152+
"Protocol requires address",
153+
string,
154+
proto.name
155+
)
149156
next_elem = sp[0]
150157
print(f"[DEBUG] Next element for value: '{next_elem}'")
151158
# First try to validate as value for current protocol
@@ -159,9 +166,12 @@ def string_iter(string: str) -> Generator[Tuple[Protocol, CodecBase, Optional[st
159166
try:
160167
# If this succeeds, it's a protocol name
161168
protocol_with_name(next_elem)
162-
# If we have a protocol that requires a value and we're seeing another protocol,
169+
# If we have a protocol that requires a value and we're seeing
170+
# another protocol,
163171
# raise a StringParseError
164-
print(f"[DEBUG] Next element '{next_elem}' is a protocol name. Error!")
172+
print(
173+
f"[DEBUG] Next element '{next_elem}' is a protocol name. Error!"
174+
)
165175
raise exceptions.StringParseError(
166176
f"Protocol {proto.name} requires a value",
167177
string,

0 commit comments

Comments
 (0)