ZackClements / berserk

Python client for the lichess API
Other
44 stars 18 forks source link

client.tournaments.get_tournament fails with TypeError #26

Closed qpwoeirut closed 1 year ago

qpwoeirut commented 2 years ago

Description

I'm trying to fetch information for one of the recent Chess960 Qualifier open arenas with client.tournaments.get_tournament.

What I Did

import berserk

client = berserk.Client()
print(client.tournaments.get_tournament("MuVtmdah"))
Traceback (most recent call last):
  File "/Users/qpwoeirut/OtherProgramming/LichessProjects/get_unique_players_in_tournament_list.py", line 4, in <module>
    print(client.tournaments.get_tournament("MuVtmdah"))
  File "/Users/qpwoeirut/OtherProgramming/LichessProjects/venv/lib/python3.9/site-packages/berserk/clients.py", line 999, in get_tournament
    return self._r.get(path, converter=models.Tournaments.convert_values)
  File "/Users/qpwoeirut/OtherProgramming/LichessProjects/venv/lib/python3.9/site-packages/berserk/session.py", line 60, in get
    return self.request('GET', *args, **kwargs)
  File "/Users/qpwoeirut/OtherProgramming/LichessProjects/venv/lib/python3.9/site-packages/berserk/session.py", line 56, in request
    return fmt.handle(response, is_stream=is_stream, converter=converter)
  File "/Users/qpwoeirut/OtherProgramming/LichessProjects/venv/lib/python3.9/site-packages/berserk/formats.py", line 35, in handle
    return converter(self.parse(response))
  File "/Users/qpwoeirut/OtherProgramming/LichessProjects/venv/lib/python3.9/site-packages/berserk/models.py", line 27, in convert_values
    data[k] = cls.convert(data[k])
  File "/Users/qpwoeirut/OtherProgramming/LichessProjects/venv/lib/python3.9/site-packages/berserk/models.py", line 16, in convert
    return cls.convert_one(data)
  File "/Users/qpwoeirut/OtherProgramming/LichessProjects/venv/lib/python3.9/site-packages/berserk/models.py", line 20, in convert_one
    for k in set(data) & set(cls.conversions):
TypeError: 'int' object is not iterable

Running client.tournaments.get works fine, if that helps. I made a quick workaround hack by changing the conversion code in models.py, but I'm not sure if that will break other things.

Original code (lines 11-16 in models.py)

class Model(metaclass=model):
    @classmethod
    def convert(cls, data):
        if isinstance(data, (list, tuple)):
            return [cls.convert_one(v) for v in data]
        return cls.convert_one(data)

Modified code

class Model(metaclass=model):
    @classmethod
    def convert(cls, data):
        if isinstance(data, (list, tuple)):
            return [cls.convert_one(v) for v in data]
        return data  # only this last line changes

Let me know if you need any more information!