PyTrakt icon indicating copy to clipboard operation
PyTrakt copied to clipboard

[python-pytrakt] Refactor: Add IdsMixin to replace extract_ids() utility method

Open glensc opened this issue 3 years ago • 7 comments
trafficstars

Extracting the "ids" on each response is tedious, and such duplication results users being confused:

  • https://github.com/moogar0880/PyTrakt/issues/78#issuecomment-1013671336
  • https://github.com/moogar0880/PyTrakt/issues/158#issuecomment-1013670394

Also, the existing extraction is inconsistent (Not applied for TVShow and Movie in this example):

  • https://github.com/moogar0880/PyTrakt/blob/8a6d4f168a858447014fb4c2c0efceb47b30ebb7/trakt/sync.py#L331-L342

This will make the ids extraction automatic, and prevent updating the attributes directly.

Additionally it came out that properties like tmdb_id, imdb_id, trakt_id are unused. they are initialized as None in the constructor but never any other value. these are commented with @deprecated and are to be removed in 4.x.

  • [x] Person
  • [x] Movie
  • [x] Calendar
  • [x] SearchResult
  • [x] TVShow
  • [x] TVEpisode
  • [x] TVSeason
  • [x] UserList

TODO:

  • [ ] rebase after https://github.com/moogar0880/PyTrakt/pull/187

glensc avatar Jan 15 '22 21:01 glensc

It's actually more confusing than that, seems the _id suffixed ones are abandoned:

  • https://github.com/moogar0880/PyTrakt/blob/8a6d4f168a858447014fb4c2c0efceb47b30ebb7/trakt/people.py#L17

as the ids property returns without the "_id":

  • https://github.com/moogar0880/PyTrakt/blob/8a6d4f168a858447014fb4c2c0efceb47b30ebb7/trakt/people.py#L70-L76

glensc avatar Jan 15 '22 21:01 glensc

Also, the existing extraction is inconsistent. not applied for TVShow and Movie in this example:

  • https://github.com/moogar0880/PyTrakt/blob/8a6d4f168a858447014fb4c2c0efceb47b30ebb7/trakt/sync.py#L331-L342

glensc avatar Jan 15 '22 21:01 glensc

Can't finish UserList as it uses namedtuple:

E   TypeError: Multiple inheritance with NamedTuple is not supported
  • https://bugs.python.org/issue36517
  • https://github.com/python/cpython/pull/19363

glensc avatar Jan 15 '22 23:01 glensc

A change is needed to namedtuple definitions (UserList):

  • remove 'trakt', 'slug'
  • add 'ids'

since namedtuple doesn't allow optional values, this would be a breaking change, meaning this needs to land in 4.x

glensc avatar Jan 16 '22 01:01 glensc

This is ready now, but not sure if this breakage is big enough that this needs to go to 4.x?

  • https://github.com/moogar0880/PyTrakt/pull/186#issuecomment-1013786115

if you're not creating UserList(...dict...) yourself, you're not affected

glensc avatar Jan 16 '22 01:01 glensc

External projects calling extract_ids(data) directly need to omit it after this PR.

glensc avatar Nov 29 '22 18:11 glensc

Merging in my fork:

  • https://github.com/glensc/python-pytrakt/pull/14

glensc avatar Dec 11 '22 14:12 glensc