VoterList
- class cometa.voting_procedures.voter_list.VoterList(ptr=None)[source]
Bases:
Sequence[Voter]Represents a list of Voters.
This class provides a collection interface for managing multiple Voters, supporting standard list operations like iteration, indexing, and slicing.
Example
>>> from cometa import VoterList, Voter >>> voter_list = VoterList() >>> voter_list.add(voter) >>> print(len(voter_list)) 1
- __getitem__(index)[source]
Gets a voter by index using bracket notation.
- Parameters:
index (int)
- Return type:
- classmethod from_list(voters)[source]
Creates a VoterList from a Python list of Voter objects.
- Parameters:
voters (list[Voter]) – A list of Voter objects.
- Returns:
A new VoterList containing all the voters.
- Raises:
CardanoError – If creation fails.
- Return type:
Example
>>> voter_list = VoterList.from_list([voter1, voter2, voter3])
- add(voter)[source]
Adds a voter to the end of the list.
- Parameters:
voter (Voter) – The Voter to add.
- Raises:
CardanoError – If addition fails.
- Return type:
None
- get(index)[source]
Retrieves a voter at the specified index.
- Parameters:
index (int) – The index of the voter to retrieve.
- Returns:
The Voter at the specified index.
- Raises:
CardanoError – If retrieval fails.
IndexError – If index is out of bounds.
- Return type:
- append(voter)[source]
Appends a voter to the end of the list (alias for add).
- Parameters:
voter (Voter) – The Voter to append.
- Raises:
CardanoError – If appending fails.
- Return type:
None
- index(value, start=0, stop=None)[source]
Returns the index of the first occurrence of value.
- Parameters:
value (Voter) – The value to search for.
start (int) – Start searching from this index.
stop (int | None) – Stop searching at this index.
- Returns:
The index of the first occurrence.
- Raises:
ValueError – If the value is not found.
- Return type:
int