Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.

Commit 9c95b9c

Browse files
lzpaptodofixthis
andauthored
Apply suggestions from code review
Co-Authored-By: Phoenix <[email protected]>
1 parent 29e01ff commit 9c95b9c

File tree

10 files changed

+32
-31
lines changed

10 files changed

+32
-31
lines changed

iota/adapter/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class BaseAdapter(object, metaclass=AdapterMeta):
153153
def __init__(self) -> None:
154154
super(BaseAdapter, self).__init__()
155155

156-
self._logger: Logger = None
156+
self._logger: Optional[Logger] = None
157157
self.local_pow: bool = False
158158

159159
@abstract_method
@@ -166,7 +166,7 @@ def get_uri(self) -> Text:
166166
)
167167

168168
@abstract_method
169-
def send_request(self, payload: Dict, **kwargs: Dict) -> Dict:
169+
def send_request(self, payload: Dict, **kwargs: Any) -> Dict:
170170
"""
171171
Sends an API request to the node.
172172
@@ -200,7 +200,7 @@ def _log(
200200
self,
201201
level: int,
202202
message: Text,
203-
context: Optional[int] = None
203+
context: Optional[dict] = None
204204
) -> None:
205205
"""
206206
Sends a message to the instance's logger, if configured.
@@ -263,7 +263,7 @@ def __init__(
263263
self,
264264
uri: Union[Text, SplitResult],
265265
timeout: Optional[int] = None,
266-
authentication: Optional[Dict] = None
266+
authentication: Optional[Tuple[Text, Text]] = None
267267
) -> None:
268268
super(HttpAdapter, self).__init__()
269269

@@ -325,7 +325,7 @@ def node_url(self) -> Text:
325325
def get_uri(self) -> Text:
326326
return self.uri.geturl()
327327

328-
async def send_request(self, payload: Dict, **kwargs: Dict) -> Dict:
328+
async def send_request(self, payload: Dict, **kwargs: Any) -> Dict:
329329
kwargs.setdefault('headers', {})
330330
for key, value in self.DEFAULT_HEADERS.items():
331331
kwargs['headers'].setdefault(key, value)
@@ -406,7 +406,7 @@ def _interpret_response(
406406
self,
407407
response: Response,
408408
payload: Dict,
409-
expected_status: Container[Dict]
409+
expected_status: Container[int]
410410
) -> Dict:
411411
"""
412412
Interprets the HTTP response from the node.
@@ -584,7 +584,7 @@ def seed_response(self, command: Text, response: Dict) -> 'MockAdapter':
584584
self.responses[command].append(response)
585585
return self
586586

587-
async def send_request(self, payload: Dict, **kwargs: Dict) -> Dict:
587+
async def send_request(self, payload: Dict, **kwargs: Any) -> Dict:
588588
"""
589589
Mimic asynchronous behavior of `HttpAdapter.send_request`.
590590
"""

iota/adapter/wrappers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get_uri(self) -> Text:
2626
return self.adapter.get_uri()
2727

2828
@abstract_method
29-
def send_request(self, payload: Dict, **kwargs: Dict) -> Dict:
29+
def send_request(self, payload: Dict, **kwargs: Any) -> Dict:
3030
raise NotImplementedError(
3131
'Not implemented in {cls}.'.format(cls=type(self).__name__),
3232
)
@@ -131,7 +131,7 @@ def get_adapter(self, command: Text) -> BaseAdapter:
131131
"""
132132
return self.routes.get(command, self.adapter)
133133

134-
async def send_request(self, payload: Dict, **kwargs: Dict) -> Dict:
134+
async def send_request(self, payload: Dict, **kwargs: Any) -> Dict:
135135
command = payload.get('command')
136136

137137
return await self.get_adapter(command).send_request(payload, **kwargs)

iota/codecs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ def get_codec_info(cls) -> CodecInfo:
5959
"""
6060
codec = cls()
6161

62-
# In Python 2, all codecs are made equal.
63-
# In Python 3, some codecs are more equal than others
6462
codec_info = {
6563
'encode': codec.encode,
6664
'decode': codec.decode,
65+
66+
# In Python 2, all codecs are made equal.
67+
# In Python 3, some codecs are more equal than others.
6768
'_is_text_encoding': False
6869
}
6970

iota/commands/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def __init__(self, adapter: BaseAdapter) -> None:
3434
self.adapter = adapter
3535

3636
self.called: bool = False
37-
self.request: Dict = None
38-
self.response: Dict = None
37+
self.request: Optional[Dict] = None
38+
self.response: Optional[Dict] = None
3939

4040
async def __call__(self, **kwargs: Any) -> Dict:
4141
"""
@@ -262,4 +262,4 @@ def _apply_filter(
262262
},
263263
)
264264

265-
return value
265+
return value

iota/crypto/kerl/conv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def convertBytesToBigInt(ba: List[int]) -> int:
9191
enumerate(reversed(bytesArray))) * signum
9292

9393

94-
def convertBigintToBytes(big: int) -> List[int]:
94+
def convertBigIntToBytes(big: int) -> List[int]:
9595
bytesArrayTemp = [(abs(big) >> pos * 8) % (1 << 8) for pos in
9696
range(48)]
9797

iota/crypto/signing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def __init__(
256256
)
257257

258258
# In order to work correctly, the seed must be padded so that it
259-
# is a multiple of 81 trytes.
259+
# is a multiple of 81 trytes.
260260
seed += b'9' * (Hash.LEN - ((len(seed) % Hash.LEN) or Hash.LEN))
261261

262262
self.security_level = security_level

iota/multisig/commands/get_digests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def get_response_filter(self):
3030

3131
# There is no async operation going on here, but the base class is async,
3232
# so from the outside, we have to act like we are doing async.
33-
async def _execute(self, request: Dict):
33+
async def _execute(self, request: Dict) -> Dict:
3434
count: Optional[int] = request['count']
3535
index: int = request['index']
3636
seed: Seed = request['seed']

iota/multisig/commands/get_private_keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_response_filter(self):
3131

3232
# There is no async operation going on here, but the base class is async,
3333
# so from the outside, we have to act like we are doing async.
34-
async def _execute(self, request: Dict):
34+
async def _execute(self, request: Dict) -> Dict:
3535
count: Optional[int] = request['count']
3636
index: int = request['index']
3737
seed: Seed = request['seed']

iota/multisig/commands/prepare_multisig_transfer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_request_filter(self) -> 'PrepareMultisigTransferRequestFilter':
3131
def get_response_filter(self):
3232
pass
3333

34-
async def _execute(self, request: Dict):
34+
async def _execute(self, request: Dict) -> Dict:
3535
change_address: Optional[Address] = request['changeAddress']
3636
multisig_input: MultisigAddress = request['multisigInput']
3737
transfers: List[ProposedTransaction] = request['transfers']

iota/transaction/base.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def __init__(
214214
:type: :py:class:`TransactionHash`
215215
"""
216216

217-
self.bundle_hash: BundleHash = bundle_hash
217+
self.bundle_hash: Optional[BundleHash] = bundle_hash
218218
"""
219219
The bundle hash, used to identify transactions that are part of the same
220220
bundle.
@@ -249,7 +249,7 @@ def __init__(
249249
:type: ``int``
250250
"""
251251

252-
self._legacy_tag: Tag = legacy_tag
252+
self._legacy_tag: Optional[Tag] = legacy_tag
253253
"""
254254
A short message attached to the transaction.
255255
@@ -259,7 +259,7 @@ def __init__(
259259
:type: :py:class:`Tag`
260260
"""
261261

262-
self.nonce: Nonce = nonce
262+
self.nonce: Optional[Nonce] = nonce
263263
"""
264264
Unique value used to increase security of the transaction hash.
265265
@@ -281,7 +281,7 @@ def __init__(
281281
:type: ``int``, unix timestamp in seconds.
282282
"""
283283

284-
self.current_index: int = current_index
284+
self.current_index: Optional[int] = current_index
285285
"""
286286
The position of the transaction inside the bundle.
287287
@@ -295,7 +295,7 @@ def __init__(
295295
:type: ``int``
296296
"""
297297

298-
self.last_index: int = last_index
298+
self.last_index: Optional[int] = last_index
299299
"""
300300
The index of the final transaction in the bundle.
301301
@@ -305,7 +305,7 @@ def __init__(
305305
:type: ``int``
306306
"""
307307

308-
self.trunk_transaction_hash: TransactionHash = trunk_transaction_hash
308+
self.trunk_transaction_hash: Optional[TransactionHash] = trunk_transaction_hash
309309
"""
310310
The transaction hash of the next transaction in the bundle.
311311
@@ -319,7 +319,7 @@ def __init__(
319319
:type: :py:class:`TransactionHash`
320320
"""
321321

322-
self.branch_transaction_hash: TransactionHash = branch_transaction_hash
322+
self.branch_transaction_hash: Optional[TransactionHash] = branch_transaction_hash
323323
"""
324324
An unrelated transaction that this transaction "approves".
325325
@@ -334,7 +334,7 @@ def __init__(
334334
:type: :py:class:`TransactionHash`
335335
"""
336336

337-
self.tag: Tag = tag
337+
self.tag: Optional[Tag] = tag
338338
"""
339339
Optional classification tag applied to this transaction.
340340
@@ -343,7 +343,7 @@ def __init__(
343343
:type: :py:class:`Tag`
344344
"""
345345

346-
self.attachment_timestamp: int = attachment_timestamp
346+
self.attachment_timestamp: Optional[int] = attachment_timestamp
347347
"""
348348
Estimated epoch time of the attachment to the tangle.
349349
@@ -352,21 +352,21 @@ def __init__(
352352
:type: ``int``, unix timestamp in milliseconds,
353353
"""
354354

355-
self.attachment_timestamp_lower_bound: int = attachment_timestamp_lower_bound
355+
self.attachment_timestamp_lower_bound: Optional[int] = attachment_timestamp_lower_bound
356356
"""
357357
The lowest possible epoch time of the attachment to the tangle.
358358
359359
:type: ``int``, unix timestamp in milliseconds.
360360
"""
361361

362-
self.attachment_timestamp_upper_bound: int = attachment_timestamp_upper_bound
362+
self.attachment_timestamp_upper_bound: Optional[int] = attachment_timestamp_upper_bound
363363
"""
364364
The highest possible epoch time of the attachment to the tangle.
365365
366366
:type: ``int``, unix timestamp in milliseconds.
367367
"""
368368

369-
self.signature_message_fragment: Fragment = signature_message_fragment
369+
self.signature_message_fragment: Optional[Fragment] = signature_message_fragment
370370
"""
371371
"Signature/Message Fragment" (note the slash):
372372

0 commit comments

Comments
 (0)