Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type hint errors #111

Closed
wthueb opened this issue Jun 27, 2022 · 8 comments · Fixed by #113
Closed

Type hint errors #111

wthueb opened this issue Jun 27, 2022 · 8 comments · Fixed by #113
Assignees
Labels
type/bug Something isn't working

Comments

@wthueb
Copy link
Contributor

wthueb commented Jun 27, 2022

Dropped v4.0.1 into my project, and decided to see what Pylance says doesn't work.

RadarrAPI.add_movie should take a db_id: Union[str, int] since IMDB IDs are strs and TMDB IDs are ints (or at least those are the types returned by RadarrAPI.lookup_movie). This propagates to RadarrAPI._movie_json and RadarrAPI.lookup_movie_by_tmdb_id.

RadarrAPI.get_tag_detail should return Union[list[dict[str, Any]], dict[str, Any]] since as the docstring points out, "Returns all tags or specific tag by database id with detailed information".

SonarrAPI.get_series should return Union[list[dict[str, Any]], dict[str, Any]]: "Returns all series in your collection or the series with the matching series ID if one is found."

Also, to import RadarrCommands, should that be exposed at the top level pyarr package? Having to do from pyarr.models.radarr import RadarrCommands seems a bit esoteric (as well as SonarrCommands).

@marksie1988 marksie1988 added the type/bug Something isn't working label Jun 27, 2022
@marksie1988
Copy link
Collaborator

Thanks, will take a look at those tomorrow morning 👍

@marksie1988 marksie1988 self-assigned this Jun 27, 2022
@github-actions
Copy link

Branch 111-type_hint_errors created!

@marksie1988
Copy link
Collaborator

After refactoring, I remember why I did this with these pieces, its due to the way MyPy reads a Union, it will error if the response is anything other than the union, even though we would expect it to accept either an int or str.

it makes sense as you are saying it could be either a str or an int, but im currently looking at a way around this, possibly with assert isinstance()

pyarr/radarr.py:56: error: Argument 1 to "lookup_movie_by_tmdb_id" of "RadarrAPI" has incompatible type "Union[str, int]"; expected "int"
pyarr/radarr.py:58: error: Argument 1 to "lookup_movie_by_imdb_id" of "RadarrAPI" has incompatible type "Union[str, int]"; expected "str"

seems others had this issue:

@wthueb
Copy link
Contributor Author

wthueb commented Jun 27, 2022

Yes I'm pretty sure the only way is to do an isinstance check. It feels a bit wrong, but it's the standard. Most APIs wouldn't make the distinction between returning an array or a single instance, as if there's just a single object it would return [obj] however we have to deal with what we're given with the APIs.

@wthueb
Copy link
Contributor Author

wthueb commented Jun 28, 2022

Mostly unrelated to this, I think there's a mixup between using db_id as a parameter like in RadarrAPI.add_movie (TMDB/IMDB ID based on tmbd: bool) and using id_ as a parameter in RadarrAPI.get_movie (also a TMDB ID, no support for IMDB ID). Meanwhile, RadarrAPI.del_movie takes an id_ which is a Radarr database ID (movie_json['id']) instead of a TMDB/IMDB ID. Not sure if this applies elsewhere in the codebase/with other APIs, these are just the functions I've noticed the mismatch.

@wthueb
Copy link
Contributor Author

wthueb commented Jun 28, 2022

Ah, one last thing. RadarrAPI.get_movie_by_movie_id is annotated as list[dict[str, Any]] when it should just be dict[str, Any].

@github-actions
Copy link

Branch 111-type_hint_errors created!

@marksie1988
Copy link
Collaborator

Mostly unrelated to this, I think there's a mixup between using db_id as a parameter like in RadarrAPI.add_movie (TMDB/IMDB ID based on tmbd: bool) and using id_ as a parameter in RadarrAPI.get_movie (also a TMDB ID, no support for IMDB ID). Meanwhile, RadarrAPI.del_movie takes an id_ which is a Radarr database ID (movie_json['id']) instead of a TMDB/IMDB ID. Not sure if this applies elsewhere in the codebase/with other APIs, these are just the functions I've noticed the mismatch.

Yes I agree there are some consistency issues with the naming of args etc. I will go through this at some point. However based on this I think the next think I look into will be setting up tests, not something ive done before but think it is necessary to avoid a lot of these issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants