PyTrakt
PyTrakt copied to clipboard
[python-pytrakt] Refactor: Add IdsMixin to replace extract_ids() utility method
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
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
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
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
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
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
External projects calling extract_ids(data) directly need to omit it after this PR.
Merging in my fork:
- https://github.com/glensc/python-pytrakt/pull/14