Skip to content

Conversation

@glensc
Copy link
Owner

@glensc glensc commented Apr 18, 2023

Thought that NamedTuple has limitations:

but apparently, @dataclass has them as well.

@glensc glensc self-assigned this Apr 18, 2023
@glensc glensc changed the title Add dataclasses dependency for Python 3.6 Refactor: Replace NamedTuple with dataclasses Apr 18, 2023
@glensc
Copy link
Owner Author

glensc commented Apr 18, 2023

The DataClassMixin trickery works for NamedTuple as well. Identically in fact.

diff --git a/trakt/users.py b/trakt/users.py
index 3d2224f..e18a67f 100644
--- a/trakt/users.py
+++ b/trakt/users.py
@@ -2,7 +2,7 @@
 """Interfaces to all of the User objects offered by the Trakt.tv API"""
 from collections import UserDict, namedtuple
 from dataclasses import dataclass, field
-from typing import Optional, Union
+from typing import Optional, Union, NamedTuple
 
 from trakt.core import delete, get, post
 from trakt.mixins import IdsMixin
@@ -64,8 +64,7 @@ def unfollow(user_name):
     yield 'users/{username}/follow'.format(username=slugify(user_name))
 
 
-@dataclass(frozen=True)
-class UserListData:
+class UserListData(NamedTuple):
     name: str
     description: str
     privacy: str

@glensc
Copy link
Owner Author

glensc commented Apr 25, 2023

Replaced by #28 and #31

@glensc glensc closed this Apr 25, 2023
@glensc glensc deleted the namedtuple-to-dataclass branch April 25, 2023 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants