ModerNews / MAL-API-Client-Upgraded

Improved version of malclient by JFryy
MIT License
2 stars 3 forks source link

Loads of errors with TypeError: 'type' object is not subscriptable #1

Closed hugoprudente closed 2 years ago

hugoprudente commented 2 years ago

Hi.

I used to use the archived MAL-API-Client, that this project is based. I have upgraded to use this project and it's failing with the TypeError

It fails installing it from PIP and using cloned from the directory.

import malclient
access_token = <secret>
client = malclient.Client(access_token=access_token, nsfw=True)
anime = client.get_seasonal_anime("summer",2022,limit=150)
len(anime)
➜ python anime_season_post.py
Traceback (most recent call last):
  File "anime_season_post.py", line 1, in <module>
    import malclient
  File "/home/hugo/MAL-API-Client-Upgraded/malclient/__init__.py", line 1, in <module>
    from .client import Client, generate_token
  File "/home/hugo/MAL-API-Client-Upgraded/malclient/client.py", line 4, in <module>
    from .anime import Anime
  File "/home/hugo/MAL-API-Client-Upgraded/malclient/anime.py", line 3, in <module>
    from .models import AnimeObject, Node, Season, PagedResult, RankingType, Sorting
  File "/home/hugo/MAL-API-Client-Upgraded/malclient/models.py", line 333, in <module>
    class AnimeObject(MALBaseModel):
  File "/home/hugo/MAL-API-Client-Upgraded/malclient/models.py", line 352, in AnimeObject
    genres: list[Genre]
TypeError: 'type' object is not subscriptable
hugoprudente commented 2 years ago

There are a lot more errors than this one, after fixing the list to List you have issues with

Traceback (most recent call last):
  File "bug.py", line 4, in <module>
    import malclient
  File "/home/hugo/MAL-API-Client-Upgraded/malclient/__init__.py", line 1, in <module>
    from .client import Client, generate_token
  File "/home/hugo/MAL-API-Client-Upgraded/malclient/client.py", line 4, in <module>
    from .anime import Anime
  File "/home/hugo/MAL-API-Client-Upgraded/malclient/anime.py", line 44, in <module>
    class Anime():
  File "/home/hugo/MAL-API-Client-Upgraded/malclient/anime.py", line 64, in Anime
    def search_anime(self, keyword: str, *, limit: int = 20, nsfw: Optional[bool] = None, anime_fields=None) -> PagedResult[Node]:
  File "/usr/lib/python3.8/typing.py", line 261, in inner
    return func(*args, **kwds)
  File "/usr/lib/python3.8/typing.py", line 897, in __class_getitem__
    _check_generic(cls, params)
  File "/home/hugo/.local/lib/python3.8/site-packages/typing_extensions.py", line 94, in _check_generic
    raise TypeError(f"{cls} is not a generic class")
TypeError: <class 'malclient.models.PagedResult'> is not a generic class

From there there are more errors depending on how you solve the PagedResult.

I'm afraid that your code at the moment is not ready to usage.

ModerNews commented 2 years ago

Hi! Thanks for your input

Regarding first issue library is developed on python 3.9 - version that deprecated typing.List type hinting method and instead introduced type hinting using generic list therefore there is no backward compatibility in library for python 3.8 and earlier. I thought that it was mentioned in Readme and docs but I will look into it.

Regarding your second issue, possibly it is compatibility issue as well, but paging is still being developed and I pushed only bare minimum so I can't say for sure, PyPi version should be more stable though. Currently I am away but I will look further into it when I am home.

ModerNews commented 2 years ago

One more thing Currently library might be hard to use due to one more issue Recently working on some side project I found out that MAL has very poor documentation and some fields might take different values than the ones in documentation, so current version of library might have some conflicts I am currently working to resolve.

hugoprudente commented 2 years ago

Hi @ModerNews thanks for the input, I'll try work with new version of python and see if everything goes fine.

If you open the issues that you know that exists I may be able to help you fix as I'm migrating my app to use your library. I mainly opened the issue as the amount of errors were not normal, and something was really going on, and now I know that is my python version!.

hugoprudente commented 2 years ago

Confirmed the fix by using python 3.9.5.

Found some other issues and created a PR for you.

ModerNews commented 2 years ago

Glad to hear that with newer version it actually works fine.

I'm migrating my app to use your library.

I'm glad to here that there are actually people using it (especially given that the API itself isn't top notch, but we can pray it will improve in future)

If you open the issues that you know that exists I may be able to help you fix

In a week, when I'm back at home I will review the code I have in local repo branch and push what is usable in a current state to have github branches synced also I will create some issues. Haven't really felt any urge to till now as there weren't any contributors other than myself

I will change the Readme installation paragraph and close the issue in few minutes.