Skip to content

Commit 6f82d44

Browse files
committed
Ruff
1 parent c0c6ef8 commit 6f82d44

File tree

4 files changed

+61
-43
lines changed

4 files changed

+61
-43
lines changed

bittensor_cli/src/bittensor/chain_data.py

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -660,12 +660,8 @@ def fix_decoded_values(cls, decoded: dict) -> "DynamicInfo":
660660
alpha_out = Balance.from_rao(decoded["alpha_out"]).set_unit(netuid)
661661
alpha_in = Balance.from_rao(decoded["alpha_in"]).set_unit(netuid)
662662
tao_in = Balance.from_rao(decoded["tao_in"]).set_unit(0)
663-
total_locked = Balance.from_rao(decoded["total_locked"]).set_unit(
664-
netuid
665-
)
666-
owner_locked = Balance.from_rao(decoded["owner_locked"]).set_unit(
667-
netuid
668-
)
663+
total_locked = Balance.from_rao(decoded["total_locked"]).set_unit(netuid)
664+
owner_locked = Balance.from_rao(decoded["owner_locked"]).set_unit(netuid)
669665
price = (
670666
Balance.from_tao(tao_in.tao / alpha_in.tao)
671667
if alpha_in.tao > 0
@@ -766,6 +762,7 @@ def alpha_to_tao_with_slippage(self, alpha: Balance) -> tuple[Balance, Balance]:
766762
@dataclass
767763
class DynamicPoolInfoV2:
768764
"""Dataclass for dynamic pool info."""
765+
769766
netuid: int
770767
alpha_issuance: int
771768
alpha_outstanding: int
@@ -836,10 +833,12 @@ def __init__(
836833
self.price = Balance.from_tao(1.0)
837834

838835
def __str__(self) -> str:
839-
return (f"DynamicPool( alpha_issuance={self.alpha_issuance}, "
840-
f"alpha_outstanding={self.alpha_outstanding}, "
841-
f"alpha_reserve={self.alpha_reserve}, "
842-
f"tao_reserve={self.tao_reserve}, k={self.k}, price={self.price} )")
836+
return (
837+
f"DynamicPool( alpha_issuance={self.alpha_issuance}, "
838+
f"alpha_outstanding={self.alpha_outstanding}, "
839+
f"alpha_reserve={self.alpha_reserve}, "
840+
f"tao_reserve={self.tao_reserve}, k={self.k}, price={self.price} )"
841+
)
843842

844843
def __repr__(self) -> str:
845844
return self.__str__()
@@ -922,6 +921,7 @@ def alpha_to_tao_with_slippage(self, alpha: Balance) -> Tuple[Balance, Balance]:
922921
@dataclass
923922
class ScheduledColdkeySwapInfo:
924923
"""Dataclass for scheduled coldkey swap information."""
924+
925925
old_coldkey: str
926926
new_coldkey: str
927927
arbitration_block: int
@@ -966,9 +966,7 @@ def decode_account_id_list(cls, vec_u8: list[int]) -> Optional[list[str]]:
966966
)
967967
if decoded is None:
968968
return None
969-
return [
970-
ss58_encode(account_id, SS58_FORMAT) for account_id in decoded
971-
]
969+
return [ss58_encode(account_id, SS58_FORMAT) for account_id in decoded]
972970

973971

974972
@dataclass
@@ -994,42 +992,56 @@ class SubnetState:
994992

995993
@classmethod
996994
def from_vec_u8(cls, vec_u8: list[int]) -> Optional["SubnetState"]:
997-
if len(vec_u8) == 0: return None
995+
if len(vec_u8) == 0:
996+
return None
998997
decoded = from_scale_encoding(vec_u8, ChainDataType.SubnetState, is_option=True)
999-
if decoded is None: return None
998+
if decoded is None:
999+
return None
10001000
return SubnetState.fix_decoded_values(decoded)
10011001

10021002
@classmethod
10031003
def list_from_vec_u8(cls, vec_u8: list[int]) -> list["SubnetState"]:
1004-
decoded = from_scale_encoding( vec_u8, ChainDataType.SubnetState, is_vec=True, is_option=True )
1005-
if decoded is None:return []
1004+
decoded = from_scale_encoding(
1005+
vec_u8, ChainDataType.SubnetState, is_vec=True, is_option=True
1006+
)
1007+
if decoded is None:
1008+
return []
10061009
decoded = [SubnetState.fix_decoded_values(d) for d in decoded]
10071010
return decoded
10081011

10091012
@classmethod
10101013
def fix_decoded_values(cls, decoded: dict) -> "SubnetState":
10111014
netuid = decoded["netuid"]
10121015
return SubnetState(
1013-
netuid = netuid,
1014-
hotkeys = [ss58_encode(val, SS58_FORMAT) for val in decoded["hotkeys"]],
1015-
coldkeys = [ss58_encode(val, SS58_FORMAT) for val in decoded["coldkeys"]],
1016-
active = decoded["active"],
1017-
validator_permit = decoded["validator_permit"],
1018-
pruning_score = [u16_normalized_float(val) for val in decoded["pruning_score"]],
1019-
last_update = decoded["last_update"],
1020-
emission = [Balance.from_rao( val ).set_unit(netuid) for val in decoded["emission"]],
1021-
dividends = [u16_normalized_float(val) for val in decoded["dividends"]],
1022-
incentives = [u16_normalized_float(val) for val in decoded["incentives"]],
1023-
consensus = [u16_normalized_float(val) for val in decoded["consensus"]],
1024-
trust = [u16_normalized_float(val) for val in decoded["trust"]],
1025-
rank = [u16_normalized_float(val) for val in decoded["rank"]],
1026-
block_at_registration = decoded["block_at_registration"],
1027-
local_stake = [Balance.from_rao( val ).set_unit(netuid) for val in decoded["local_stake"]],
1028-
global_stake = [Balance.from_rao( val ).set_unit(0) for val in decoded["global_stake"]],
1029-
stake_weight = [u16_normalized_float(val) for val in decoded["stake_weight"]],
1030-
emission_history = decoded["emission_history"]
1016+
netuid=netuid,
1017+
hotkeys=[ss58_encode(val, SS58_FORMAT) for val in decoded["hotkeys"]],
1018+
coldkeys=[ss58_encode(val, SS58_FORMAT) for val in decoded["coldkeys"]],
1019+
active=decoded["active"],
1020+
validator_permit=decoded["validator_permit"],
1021+
pruning_score=[
1022+
u16_normalized_float(val) for val in decoded["pruning_score"]
1023+
],
1024+
last_update=decoded["last_update"],
1025+
emission=[
1026+
Balance.from_rao(val).set_unit(netuid) for val in decoded["emission"]
1027+
],
1028+
dividends=[u16_normalized_float(val) for val in decoded["dividends"]],
1029+
incentives=[u16_normalized_float(val) for val in decoded["incentives"]],
1030+
consensus=[u16_normalized_float(val) for val in decoded["consensus"]],
1031+
trust=[u16_normalized_float(val) for val in decoded["trust"]],
1032+
rank=[u16_normalized_float(val) for val in decoded["rank"]],
1033+
block_at_registration=decoded["block_at_registration"],
1034+
local_stake=[
1035+
Balance.from_rao(val).set_unit(netuid) for val in decoded["local_stake"]
1036+
],
1037+
global_stake=[
1038+
Balance.from_rao(val).set_unit(0) for val in decoded["global_stake"]
1039+
],
1040+
stake_weight=[u16_normalized_float(val) for val in decoded["stake_weight"]],
1041+
emission_history=decoded["emission_history"],
10311042
)
10321043

1044+
10331045
class SubstakeElements:
10341046
@staticmethod
10351047
def decode(result: list[int]) -> list[dict]:
@@ -1049,7 +1061,6 @@ def decode(result: list[int]) -> list[dict]:
10491061
return result
10501062

10511063

1052-
10531064
custom_rpc_type_registry = {
10541065
"types": {
10551066
"SubnetInfo": {

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ def read_requirements(path):
6464
long_description_content_type="text/markdown",
6565
url="https://github.com/opentensor/btcli",
6666
author="bittensor.com",
67-
packages=find_packages(exclude=["tests", "tests.*", "*/tests/*", "*/tests"]) + ['bittensor_cli.src.bittensor.templates'],
67+
packages=find_packages(exclude=["tests", "tests.*", "*/tests/*", "*/tests"])
68+
+ ["bittensor_cli.src.bittensor.templates"],
6869
include_package_data=True,
6970
package_data={
7071
"": ["templates/*"],

tests/e2e_tests/test_senate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def test_senate(local_chain, wallet_setup):
8888

8989
# Assert Bob is now part of the senate
9090
assert wallet_bob.hotkey.ss58_address in root_senate_after_reg.stdout
91-
91+
9292
# Manually add a proposal on the chain & assert
9393
success = asyncio.run(call_add_proposal(local_chain, wallet_bob))
9494
assert success is True
@@ -154,10 +154,10 @@ def test_senate(local_chain, wallet_setup):
154154
assert proposals_after_aye_output[5] == "Aye"
155155

156156
# Aye votes increased to 1
157-
assert proposals_after_aye_output[2] == '1'
157+
assert proposals_after_aye_output[2] == "1"
158158

159159
# Nay votes remain 0
160-
assert proposals_after_aye_output[3] == '0'
160+
assert proposals_after_aye_output[3] == "0"
161161

162162
# Register Alice to the root network (0)
163163
# Registering to root automatically makes you a senator if eligible

tests/e2e_tests/utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
from bittensor_wallet import Wallet
1212

1313
if TYPE_CHECKING:
14-
from bittensor_cli.src.bittensor.async_substrate_interface import AsyncSubstrateInterface
14+
from bittensor_cli.src.bittensor.async_substrate_interface import (
15+
AsyncSubstrateInterface,
16+
)
1517

1618
template_path = os.getcwd() + "/neurons/"
1719
templates_repo = "templates repository"
@@ -287,7 +289,9 @@ def uninstall_templates(install_dir):
287289
shutil.rmtree(install_dir)
288290

289291

290-
async def call_add_proposal(substrate: "AsyncSubstrateInterface", wallet: Wallet) -> bool:
292+
async def call_add_proposal(
293+
substrate: "AsyncSubstrateInterface", wallet: Wallet
294+
) -> bool:
291295
async with substrate:
292296
proposal_call = await substrate.compose_call(
293297
call_module="System",
@@ -304,7 +308,9 @@ async def call_add_proposal(substrate: "AsyncSubstrateInterface", wallet: Wallet
304308
},
305309
)
306310

307-
extrinsic = await substrate.create_signed_extrinsic(call=call, keypair=wallet.coldkey)
311+
extrinsic = await substrate.create_signed_extrinsic(
312+
call=call, keypair=wallet.coldkey
313+
)
308314
response = await substrate.submit_extrinsic(
309315
extrinsic,
310316
wait_for_inclusion=True,

0 commit comments

Comments
 (0)