Skip to content

Commit

Permalink
Monkey patch trakt UserList with a type field
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Oct 16, 2022
1 parent aed8357 commit 332c910
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions plextraktsync/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Factory:
def trakt_api(self):
from plextraktsync.trakt_api import TraktApi

self.monkey_patch_trakt()

config = self.run_config()
trakt = TraktApi(batch_delay=config.batch_delay)

Expand Down Expand Up @@ -137,5 +139,23 @@ def config(self):

return CONFIG

@staticmethod
def monkey_patch_trakt():
from collections import namedtuple

import trakt.users

# Add `type` to UserList named tuple:
# - https://github.com/moogar0880/PyTrakt/pull/206
# Monkey patch the class:
# - https://stackoverflow.com/a/28500620/2314626
# - https://stackoverflow.com/a/62160225/2314626
UserListTuple = namedtuple('UserList', trakt.users.UserList._fields + ('type',))

class UserList(UserListTuple, trakt.users.UserList):
pass

trakt.users.UserList = UserList


factory = Factory()

0 comments on commit 332c910

Please sign in to comment.