Skip to content

Commit 745a126

Browse files
author
Roman
committed
to be consistent + setter
1 parent f46a249 commit 745a126

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

bittensor/core/subtensor_api/__init__.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
from .commitments import Commitments as _Commitments
77
from .delegates import Delegates as _Delegates
88
from .extrinsics import Extrinsics as _Extrinsics
9-
from .metagraph import Metagraphs as _Metagraphs
9+
from .metagraphs import Metagraphs as _Metagraphs
1010
from .neurons import Neurons as _Neurons
1111
from .queries import Queries as _Queries
1212
from .stakes import Stakes as _Stakes
13-
from .subnet import Subnet as _Subnet
14-
from .wallet import Wallet as _Wallet
13+
from .subnets import Subnets as _Subnets
14+
from .utils import add_classic_fields as _add_classic_fields
15+
from .wallets import Wallets as _Wallets
1516

1617
if TYPE_CHECKING:
1718
from bittensor.core.config import Config
@@ -23,8 +24,9 @@ class SubtensorApi:
2324
Arguments:
2425
network: The network to connect to. Defaults to `None` -> `finney`.
2526
config: Bittensor configuration object. Defaults to `None`.
26-
log_verbose: If true, sets the subtensor to log verbosely. Defaults to `False`.
27-
async_subtensor: If true, uses the async subtensor to create the connection. Defaults to `False`.
27+
log_verbose: If `True`, sets the subtensor to log verbosely. Defaults to `False`.
28+
async_subtensor: If `True`, uses the async subtensor to create the connection. Defaults to `False`.
29+
subtensor_fields: If `True`, all methods from the Subtensor class will be added to the root level of this class.
2830
2931
Example:
3032
# sync version
@@ -43,6 +45,12 @@ class SubtensorApi:
4345
print(await subtensor.block)
4446
print(await subtensor.delegates.get_delegate_identities())
4547
print(await subtensor.chain.tx_rate_limit())
48+
49+
# using `subtensor_fields`
50+
import bittensor as bt
51+
52+
subtensor = bt.SubtensorApi(subtensor_fields=True)
53+
print(subtensor.bonds(0))
4654
"""
4755

4856
def __init__(
@@ -51,6 +59,7 @@ def __init__(
5159
config: Optional["Config"] = None,
5260
log_verbose: bool = False,
5361
async_subtensor: bool = False,
62+
subtensor_fields: bool = False,
5463
_mock: bool = False,
5564
):
5665
self.network = network
@@ -60,6 +69,9 @@ def __init__(
6069
self._config = config
6170
self._subtensor = self._get_subtensor()
6271

72+
# fix naming collision
73+
self._neurons = _Neurons(self._subtensor)
74+
6375
# define empty fields
6476
self.substrate = self._subtensor.substrate
6577
self.add_args = self._subtensor.add_args
@@ -74,6 +86,8 @@ def __init__(
7486
self.sign_and_send_extrinsic = self._subtensor.sign_and_send_extrinsic
7587
self.start_call = self._subtensor.start_call
7688
self.wait_for_block = self._subtensor.wait_for_block
89+
if subtensor_fields:
90+
_add_classic_fields(self)
7791

7892
def _get_subtensor(self) -> Union["_Subtensor", "_AsyncSubtensor"]:
7993
"""Returns the subtensor instance based on the provided config and subtensor type flag."""
@@ -136,7 +150,11 @@ def metagraphs(self):
136150

137151
@property
138152
def neurons(self):
139-
return _Neurons(self._subtensor)
153+
return self._neurons
154+
155+
@neurons.setter
156+
def neurons(self, value):
157+
self._neurons = value
140158

141159
@property
142160
def queries(self):
@@ -147,9 +165,9 @@ def stakes(self):
147165
return _Stakes(self._subtensor)
148166

149167
@property
150-
def subnet(self):
151-
return _Subnet(self._subtensor)
168+
def subnets(self):
169+
return _Subnets(self._subtensor)
152170

153171
@property
154-
def wallet(self):
155-
return _Wallet(self._subtensor)
172+
def wallets(self):
173+
return _Wallets(self._subtensor)

0 commit comments

Comments
 (0)