From 8ebb0228902eb75f301fe8090c199389db407e35 Mon Sep 17 00:00:00 2001 From: rawsun007 Date: Wed, 16 Sep 2026 15:16:32 +0530 Subject: [PATCH 1/2] Add __len__ to UserList PublicList defines both __iter__ and __len__; UserList defines only __iter__, so len() on a user list raises TypeError and callers have to materialise the iterator to count it. Co-authored-by: Claude Opus 5 --- trakt/users.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/trakt/users.py b/trakt/users.py index 1a4c6ed..5c728f6 100644 --- a/trakt/users.py +++ b/trakt/users.py @@ -214,6 +214,10 @@ def __iter__(self): """Iterate over the items in this user list""" return self._items.__iter__() + def __len__(self): + """Return the number of items in this user list""" + return len(self._items) + @classmethod @post def create(cls, name, creator, description=None, privacy='private', From f63cad6ec9a7d5773d12b9096f7c2a2e2c6ff3b3 Mon Sep 17 00:00:00 2001 From: rawsun007 Date: Wed, 16 Sep 2026 15:16:32 +0530 Subject: [PATCH 2/2] Assert len() agrees with iteration on a UserList Co-authored-by: Claude Opus 5 --- tests/test_users.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_users.py b/tests/test_users.py index 1e85384..74a1eca 100644 --- a/tests/test_users.py +++ b/tests/test_users.py @@ -62,6 +62,9 @@ def test_user_list(): instancetypes = (Movie, TVShow, TVSeason, TVEpisode, Person) assert all([isinstance(k, instancetypes) for k in l]) + # len() agrees with what iteration yields + assert len(l) == len(list(l)) + # PUT to add and remove items from list l.add_items() for k, v in data.items():