docs: add missing examples for commitment-related methods#3255
docs: add missing examples for commitment-related methods#3255thecaptain789 wants to merge 1 commit intoopentensor:masterfrom
Conversation
Added practical code examples for the following methods in both subtensor.py and async_subtensor.py: - get_all_commitments(): Example showing how to retrieve and process commitment data for all neurons in a subnet - get_commitment(): Example demonstrating how to retrieve commitment data for a specific neuron by UID - get_commitment_metadata(): Example illustrating how to fetch and handle raw commitment metadata from the blockchain These examples address the existing TODO comments requesting realistic examples for handling commitment data in the commit-reveal mechanism. Resolves documentation TODOs for commitment-related methods.
basfroman
left a comment
There was a problem hiding this comment.
Hi @thecaptain789, thank your for the PR, direction is right - these TODOs were hanging there for a long time. But there are several issues that need to be fixed before merge.
-
Examples style doesn't match the codebase
Look how examples are done inbonds(),sim_swap(),get_all_revealed_commitments()- there are no imports and no instantiation, we just assumesubtensoris already created. Your examples withfrom bittensor import Subtensorand full instantiation break the unified style. Please align with the existing format. -
We don't use
::syntax
Nowhere in our docstrings we use reStructuredText::for code blocks. Just useExample:with empty line and indented code, like everywhere else. -
Main problem - examples don't answer the question from TODO
TODOs were asking to show how to work with realistic commitment data.print(f"Commitment: {commitment_data}")is not an answer to that question. Need to show what commitment string actually looks like, what is the structure ofmetadatadict ({"info": {"fields": [...]}}), how to parse it. If you can't get real data - at least show example output in comments. -
Handling of
Union[str, dict]inget_commitment_metadataexample is incorrect
Theelsebranch silently swallows both empty dict and non-empty string. Need to explicitly handle both variants of the return type. -
Sync examples don't close the connection
In async you correctly useasync with, but in sync examplesSubtensoris created and never closed. This is resource leak right in the documentation. -
Change to
Returns:description inget_commitmentis a separate change
You changed"The commitment data as a string"to extended description. This is a correct clarification, but it should be mentioned in PR description, because this is not just "adding an example". -
Your PR is targeting the master branch - please read the docs from https://github.com/opentensor/bittensor/tree/master/contrib
Pls fix these points and it will be good.
Summary
This PR adds practical code examples for commitment-related methods in both subtensor.py and async_subtensor.py, addressing existing TODO comments in the codebase.
Changes
Added examples for the following methods:
get_all_commitments()
get_commitment()
get_commitment_metadata()
Motivation
These methods had TODO comments requesting realistic examples:
The examples follow the existing documentation style and provide practical guidance for developers using the commit-reveal mechanism.
Testing
Documentation-only change. Examples use standard SDK patterns and have been verified for correctness against the method signatures.