jontingvold / pyrankvote

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

Library no longer works with latest python version (3.10.7) #24

Closed Danyc0 closed 1 year ago

Danyc0 commented 1 year ago

I'm using pyrankvote v2.0.5 straight from pip, and I've just updated to python v3.10.7 but now my previously working projects using the library no longer work. My first test was to try to run the example code in the README, and that errored in the same way as my code, as follows:

Traceback (most recent call last):
  File "/home/dan/test/main.py", line 30, in <module>
    print(election_result)
  File "/home/dan/test/env/lib/python3.10/site-packages/pyrankvote/helpers.py", line 402, in __str__
    lines.append(round_.__str__())
  File "/home/dan/test/env/lib/python3.10/site-packages/pyrankvote/helpers.py", line 57, in __str__
    pretty_print_string = tabulate(
  File "/home/dan/test/env/lib/python3.10/site-packages/tabulate/__init__.py", line 2051, in tabulate
    list_of_lists, separating_lines = _remove_separating_lines(list_of_lists)
  File "/home/dan/test/env/lib/python3.10/site-packages/tabulate/__init__.py", line 1265, in _remove_separating_lines
    if _is_separating_line(row):
  File "/home/dan/test/env/lib/python3.10/site-packages/tabulate/__init__.py", line 107, in _is_separating_line
    (len(row) >= 1 and row[0] == SEPARATING_LINE)
  File "/home/dan/test/env/lib/python3.10/site-packages/pyrankvote/models.py", line 28, in __eq__
    return self.name == other.name
AttributeError: 'str' object has no attribute 'name'

Thanks, Dan

Danyc0 commented 1 year ago

After a bit of digging, it looks like I was pulling down tabulate v0.9.0, which may be the cause of the issue, but if I downgrade to tabulate v0.8.7 as required by requirements.txt, we then get a new error, which seems to root in tabulates use of the Iterable abstract class, which was deprecated in python 3.10. The new error is as follows:

Traceback (most recent call last):
  File "/home/dan/test/main.py", line 1, in <module>
    import pyrankvote
  File "/home/dan/test/env/lib/python3.10/site-packages/pyrankvote/__init__.py", line 2, in <module>
    from pyrankvote.single_seat_ranking_methods import instant_runoff_voting
  File "/home/dan/test/env/lib/python3.10/site-packages/pyrankvote/single_seat_ranking_methods.py", line 8, in <module>
    from pyrankvote.helpers import CompareMethodIfEqual, ElectionResults
  File "/home/dan/test/env/lib/python3.10/site-packages/pyrankvote/helpers.py", line 10, in <module>
    from tabulate import tabulate
  File "/home/dan/test/env/lib/python3.10/site-packages/tabulate.py", line 16, in <module>
    from collections import Iterable
ImportError: cannot import name 'Iterable' from 'collections' (/usr/lib/python3.10/collections/__init__.py)

which looks like it's caused by a silly version comparison which doesn't work with python v3.10, which is fixed in tabulate v0.9.0, and if I fix it in v0.8.7, pyrankvote bursts back into life

jontingvold commented 1 year ago

Thanks for your report. I will take a look at it tomorrow.

jontingvold commented 1 year ago

I have know fixed the issue in newly released version 2.0.6 that has been published on PyPi/pip today.