jontingvold / pyrankvote

PyRankVote is a python library for different ranked-choice voting systems, like IRV, STV and PBV. Created in June 2019.
MIT License
53 stars 16 forks source link

fix bug blocking >256 candidates #15

Closed dorbarker closed 3 years ago

dorbarker commented 3 years ago

Fixes a bug blocking elections with greater than 256 candidates. The check by Ballot._is_duplicates() to see if there are duplicated candidates on the ballot uses is not instead of !=.

The trouble is that in Python, is compares object identity. Integers in the interval [-5, 256] are singleton objects, and numbers outside that range are not.

a = 10
b = 10
a is b
# True

x = 257
y = 257
x is y 
# False