Skip to content

Commit 8685ac8

Browse files
steinerkelvinclaude
andcommitted
fix: correct typos and improve Pydantic v2 compatibility
- Fix typo: tranformed_modules β†’ transformed_modules in cli/_common.py - Update docstrings and model field iterations for Pydantic v2 - Clean up imports and formatting consistency πŸ€– Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent b5f7abd commit 8685ac8

File tree

7 files changed

+19
-20
lines changed

7 files changed

+19
-20
lines changed

β€Žsrc/torusdk/__init__.pyβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""
2-
The Torus CLI library package.
2+
Official Torus SDK library for Python.
33
44
Submodules:
5-
* `torus.client`: A lightweigh yet faster client for the Torus Network.
6-
* `.compat`: Compatibility layer for the *classic* `commune` library.
5+
* `torus.client`: A lightweight client for the Torus Network.
76
* `.types`: Torus common types.
87
* `.key`: Key related functions.
8+
* `.compat`: Compatibility layer for the classic library.
99
1010
.. include:: ../../README.md
1111
"""

β€Žsrc/torusdk/cli/_common.pyβ€Ž

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
)
3131

3232
NOT_IMPLEMENTED_MESSAGE = (
33-
"method not available. "
34-
"It's going to be rolled out in the coming updates."
33+
"method not available. It's going to be rolled out in the coming updates."
3534
)
3635

3736
HIDE_FEATURES = False
@@ -315,7 +314,7 @@ def render_pydantic_subtable(value: BaseModel | dict[Any, Any]) -> Table:
315314
border_style="bright_black",
316315
)
317316
if isinstance(value, BaseModel):
318-
for subfield_name, _ in value.model_fields.items():
317+
for subfield_name, _ in value.__class__.model_fields.items():
319318
subfield_value = getattr(value, subfield_name)
320319
subtable.add_row(f"{subfield_name}: {subfield_value}")
321320
else:
@@ -345,7 +344,7 @@ def render_single_pydantic_object(
345344
table.add_column("Field", style="white", vertical="middle")
346345
table.add_column("Value", style="white", vertical="middle")
347346

348-
for field_name, _ in obj.model_fields.items():
347+
for field_name, _ in obj.__class__.model_fields.items():
349348
value = getattr(obj, field_name)
350349
if isinstance(value, BaseModel):
351350
subtable = render_pydantic_subtable(value)
@@ -386,14 +385,14 @@ def render_pydantic_table(
386385
title_style="bold magenta",
387386
)
388387

389-
for field_name, _ in objects[0].model_fields.items():
388+
for field_name, _ in objects[0].__class__.model_fields.items():
390389
if field_name in ignored_columns:
391390
continue
392391
table.add_column(field_name, style="white", vertical="middle")
393392

394393
for obj in objects:
395394
row_data: list[str | Table] = []
396-
for field_name, _ in obj.model_fields.items():
395+
for field_name, _ in obj.__class__.model_fields.items():
397396
if field_name in ignored_columns:
398397
continue
399398
value = getattr(obj, field_name)
@@ -486,19 +485,19 @@ def print_module_info(
486485
)
487486

488487
to_exclude = ["stake_from", "regblock"]
489-
tranformed_modules = transform_module_into(
488+
transformed_modules = transform_module_into(
490489
to_exclude, last_block, immunity_period, agents
491490
)
492491

493-
sample_mod = tranformed_modules[0]
492+
sample_mod = transformed_modules[0]
494493
for key in sample_mod.keys():
495494
# add columns
496495
table.add_column(key, style="white")
497496

498497
total_stake = 0
499498
total_balance = 0
500499

501-
for mod in tranformed_modules:
500+
for mod in transformed_modules:
502501
total_stake += mod["stake"]
503502
if mod.get("balance") is not None:
504503
total_balance += mod["balance"]
@@ -520,7 +519,7 @@ def get_universal_password(ctx: CustomCtx) -> str:
520519
return universal_password
521520

522521

523-
def tranform_network_params(params: dict[str, Any]):
522+
def transform_network_params(params: dict[str, Any]):
524523
"""Transform network params to be human readable."""
525524
params_ = params
526525
general_params = dict_from_nano(

β€Žsrc/torusdk/cli/key.pyβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def create(
5555
"""
5656
context = make_custom_context(ctx)
5757

58-
5958
if key_name_exists(name):
6059
context.info(f"WARNING! Key '{name}' already exists", style="bold")
6160
if not context.confirm("Are you sure you want to override it?"):

β€Žsrc/torusdk/client.pyβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,9 @@ def query_map_proposals(
19641964

19651965
def query_map_weights(
19661966
self, extract_value: bool = False
1967-
) -> dict[Ss58Address, dict[str, list[tuple[Ss58Address, int]] | int]] | None:
1967+
) -> (
1968+
dict[Ss58Address, dict[str, list[tuple[Ss58Address, int]] | int]] | None
1969+
):
19681970
"""
19691971
Retrieves a mapping of weights for keys on the network.
19701972

β€Žsrc/torusdk/faucet/powv2.pyβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import hashlib
22
import math
33
import multiprocessing
4-
import multiprocessing.queues
54
import multiprocessing.synchronize
65
import os
76
import threading

β€Žsrc/torusdk/key.pyβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ def check_ss58_address(
136136
AssertionError: If the address is invalid.
137137
"""
138138

139-
assert is_ss58_address(
140-
address, ss58_format
141-
), f"Invalid SS58 address '{address}'"
139+
assert is_ss58_address(address, ss58_format), (
140+
f"Invalid SS58 address '{address}'"
141+
)
142142
return Ss58Address(address)
143143

144144

β€Žsrc/torusdk/misc.pyβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def get_fees(c_client: TorusClient):
143143

144144
def get_global_params(c_client: TorusClient):
145145
"""
146-
Returns global parameters of the whole commune ecosystem
146+
Returns global parameters of the whole Torus network
147147
"""
148148

149149
query_all = c_client.query_batch(

0 commit comments

Comments
Β (0)