diff --git a/bittensor/core/async_subtensor.py b/bittensor/core/async_subtensor.py index 71013e2ba5..1dee258313 100644 --- a/bittensor/core/async_subtensor.py +++ b/bittensor/core/async_subtensor.py @@ -1480,9 +1480,9 @@ async def get_metagraph_info( Retrieves full or partial metagraph information for the specified subnet (netuid). Arguments: - netuid (int): The NetUID of the subnet to query. - field_indices (Optional[list[SelectiveMetagraphIndex]]): An optional list of SelectiveMetagraphIndex values - specifying which fields to retrieve. If not provided, all available fields will be returned. + netuid: The NetUID of the subnet to query. + field_indices: An optional list of SelectiveMetagraphIndex values specifying which fields to retrieve. If + not provided, all available fields will be returned. block: the block number at which to retrieve the hyperparameter. Do not specify if using block_hash or reuse_block block_hash: The hash of blockchain block number for the query. Do not specify if using @@ -1505,9 +1505,12 @@ async def get_metagraph_info( if field_indices: if isinstance(field_indices, list) and all( - isinstance(f, SelectiveMetagraphIndex) for f in field_indices + isinstance(f, (SelectiveMetagraphIndex, int)) for f in field_indices ): - indexes = [f.value for f in field_indices] + indexes = [ + f.value if isinstance(f, SelectiveMetagraphIndex) else f + for f in field_indices + ] else: raise ValueError( "`field_indices` must be a list of SelectiveMetagraphIndex items." diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index 2a90707a81..29fc857e2e 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -1133,18 +1133,18 @@ def get_minimum_required_stake(self) -> Balance: def get_metagraph_info( self, netuid: int, - field_indices: Optional[list["SelectiveMetagraphIndex"]] = None, + field_indices: Optional[list[Union["SelectiveMetagraphIndex", int]]] = None, block: Optional[int] = None, ) -> Optional[MetagraphInfo]: """ Retrieves full or partial metagraph information for the specified subnet (netuid). Arguments: - netuid (int): The NetUID of the subnet to query. - field_indices (Optional[list[SelectiveMetagraphIndex]]): An optional list of SelectiveMetagraphIndex values - specifying which fields to retrieve. If not provided, all available fields will be returned. - block (Optional[int]):The block number at which to query the data. If not specified, the current block or - one determined via reuse_block or block_hash will be used. + netuid: The NetUID of the subnet to query. + field_indices: An optional list of SelectiveMetagraphIndex values specifying which fields to retrieve. If + not provided, all available fields will be returned. + block: The block number at which to query the data. If not specified, the current block or one determined + via reuse_block or block_hash will be used. Returns: Optional[MetagraphInfo]: A MetagraphInfo object containing the requested subnet data, or None if the subnet @@ -1162,9 +1162,12 @@ def get_metagraph_info( if field_indices: if isinstance(field_indices, list) and all( - isinstance(f, SelectiveMetagraphIndex) for f in field_indices + isinstance(f, (SelectiveMetagraphIndex, int)) for f in field_indices ): - indexes = [f.value for f in field_indices] + indexes = [ + f.value if isinstance(f, SelectiveMetagraphIndex) else f + for f in field_indices + ] else: raise ValueError( "`field_indices` must be a list of SelectiveMetagraphIndex items." diff --git a/bittensor/utils/easy_imports.py b/bittensor/utils/easy_imports.py index cc81efe3d2..ea0e72bce9 100644 --- a/bittensor/utils/easy_imports.py +++ b/bittensor/utils/easy_imports.py @@ -47,6 +47,7 @@ ProposalCallData, ProposalVoteData, ScheduledColdkeySwapInfo, + SelectiveMetagraphIndex, StakeInfo, SubnetHyperparameters, SubnetIdentity, diff --git a/tests/unit_tests/test_async_subtensor.py b/tests/unit_tests/test_async_subtensor.py index 07d3c4e98c..0c4e4587e8 100644 --- a/tests/unit_tests/test_async_subtensor.py +++ b/tests/unit_tests/test_async_subtensor.py @@ -3100,7 +3100,7 @@ async def test_get_metagraph_info_specific_fields(subtensor, mocker): # Preps netuid = 1 mock_value = {"mock": "data"} - fields = [SelectiveMetagraphIndex.Name, SelectiveMetagraphIndex.OwnerHotkey] + fields = [SelectiveMetagraphIndex.Name, 5] mock_runtime_call = mocker.patch.object( subtensor.substrate, @@ -3119,7 +3119,13 @@ async def test_get_metagraph_info_specific_fields(subtensor, mocker): mock_runtime_call.assert_awaited_once_with( "SubnetInfoRuntimeApi", "get_selective_metagraph", - params=[netuid, [0] + [f.value for f in fields]], + params=[ + netuid, + [0] + + [ + f.value if isinstance(f, SelectiveMetagraphIndex) else f for f in fields + ], + ], block_hash=await subtensor.determine_block_hash(None), ) mock_from_dict.assert_called_once_with(mock_value) @@ -3131,8 +3137,8 @@ async def test_get_metagraph_info_specific_fields(subtensor, mocker): [ "invalid", ], - [SelectiveMetagraphIndex.Active, 1], - [1, 2, 3], + [SelectiveMetagraphIndex.Active, 1, "f"], + [1, 2, 3, "f"], ], ) @pytest.mark.asyncio diff --git a/tests/unit_tests/test_subtensor.py b/tests/unit_tests/test_subtensor.py index 0d5f418170..015884a831 100644 --- a/tests/unit_tests/test_subtensor.py +++ b/tests/unit_tests/test_subtensor.py @@ -3428,7 +3428,7 @@ def test_get_metagraph_info_specific_fields(subtensor, mocker): # Preps netuid = 1 mock_value = {"mock": "data"} - fields = [SelectiveMetagraphIndex.Name, SelectiveMetagraphIndex.OwnerHotkey] + fields = [SelectiveMetagraphIndex.Name, 5] mock_runtime_call = mocker.patch.object( subtensor.substrate, @@ -3447,7 +3447,13 @@ def test_get_metagraph_info_specific_fields(subtensor, mocker): mock_runtime_call.assert_called_once_with( "SubnetInfoRuntimeApi", "get_selective_metagraph", - params=[netuid, [0] + [f.value for f in fields]], + params=[ + netuid, + [0] + + [ + f.value if isinstance(f, SelectiveMetagraphIndex) else f for f in fields + ], + ], block_hash=subtensor.determine_block_hash(None), ) mock_from_dict.assert_called_once_with(mock_value) @@ -3459,8 +3465,8 @@ def test_get_metagraph_info_specific_fields(subtensor, mocker): [ "invalid", ], - [SelectiveMetagraphIndex.Active, 1], - [1, 2, 3], + [SelectiveMetagraphIndex.Active, 1, "f"], + [1, 2, 3, "f"], ], ) def test_get_metagraph_info_invalid_field_indices(subtensor, wrong_fields):