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
__init__(ptr=None)[source]
Return type:

None

__enter__()[source]
Return type:

VoterList

__exit__(exc_type, exc_val, exc_tb)[source]
Return type:

None

__repr__()[source]

Return repr(self).

Return type:

str

__len__()[source]

Returns the number of voters in the list.

Return type:

int

__iter__()[source]

Iterates over all voters in the list.

Return type:

Iterator[Voter]

__getitem__(index)[source]

Gets a voter by index using bracket notation.

Parameters:

index (int)

Return type:

Voter

__bool__()[source]

Returns True if the list is not empty.

Return type:

bool

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:

VoterList

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:

Voter

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

count(value)[source]

Returns the number of occurrences of value.

Parameters:

value (Voter) – The value to count.

Returns:

The number of occurrences.

Return type:

int