ConverterBallotGeneral

class whalrus.ConverterBallotGeneral(plurality_priority: whalrus.priorities.priority.Priority = Priority.UNAMBIGUOUS, veto_priority: whalrus.priorities.priority.Priority = Priority.UNAMBIGUOUS, one_name_priority: whalrus.priorities.priority.Priority = Priority.UNAMBIGUOUS)[source]

General ballot converter.

This is a default general converter. It tries to infer the type of input and converts it to an object of the relevant subclass of Ballot.

Parameters

Examples

Typical usage:

>>> converter = ConverterBallotGeneral()
>>> converter({'a': 10, 'b': 7, 'c': 0})
BallotLevels({'a': 10, 'b': 7, 'c': 0}, candidates={'a', 'b', 'c'}, scale=Scale())
>>> converter([{'a', 'b'}, {'c'}])
BallotOrder([{'a', 'b'}, 'c'], candidates={'a', 'b', 'c'})
>>> converter('a ~ b > c')
BallotOrder([{'a', 'b'}, 'c'], candidates={'a', 'b', 'c'})
>>> converter('Alice')
BallotOneName('Alice', candidates={'Alice'})

It is also possible to “restrict” the set of candidates on-the-fly:

>>> converter = ConverterBallotGeneral()
>>> converter('a ~ b > c', candidates={'b', 'c'})
BallotOrder(['b', 'c'], candidates={'b', 'c'})
>>> converter({'a': 10, 'b': 7, 'c': 0}, candidates={'b', 'c'})
BallotLevels({'b': 7, 'c': 0}, candidates={'b', 'c'}, scale=Scale())

Cf. Ballot.restrict() for more information.

Use options for the restrictions:

>>> converter = ConverterBallotGeneral(one_name_priority=Priority.ASCENDING,
...                                    plurality_priority=Priority.ASCENDING,
...                                    veto_priority=Priority.ASCENDING)
>>> converter(BallotOneName('a', candidates={'a', 'b', 'c'}), candidates={'b', 'c'})
BallotOneName('b', candidates={'b', 'c'})
>>> converter(BallotPlurality('a', candidates={'a', 'b', 'c'}), candidates={'b', 'c'})
BallotPlurality('b', candidates={'b', 'c'})
>>> converter(BallotVeto('a', candidates={'a', 'b', 'c'}), candidates={'b', 'c'})
BallotVeto('c', candidates={'b', 'c'})