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

Typing issues with upgrade from pyarr 3.1.3 -> 5.2.0 #162

Open
2 tasks done
wthueb opened this issue Jul 31, 2023 · 0 comments
Open
2 tasks done

Typing issues with upgrade from pyarr 3.1.3 -> 5.2.0 #162

wthueb opened this issue Jul 31, 2023 · 0 comments
Labels
type/bug Something isn't working

Comments

@wthueb
Copy link
Contributor

wthueb commented Jul 31, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Current Behaviour

I think I've discovered a few different issues after updating my pyarr dependency in one of my projects. Note that all of these are errors according to Pylance/Pyright.

  1. RescanMovie is not a member of RadarrCommands, but it is in the doctext for it, and it is a valid command.

  2. The type hint for the **kwargs for RadarrAPI.post_command should just be Union[int, list[int]], otherwise you get the following error:

Argument of type "int" cannot be assigned to parameter "movieId" of type "dict[str, int | list[int]] | None" in function "post_command"
  Type "int" cannot be assigned to type "dict[str, int | list[int]] | None"
    "int" is incompatible with "dict[str, int | list[int]]"
    Type cannot be assigned to type "None" Pylance[reportGeneralTypeIssues]
(parameter) movie_id: int

The resulting usage within the function would be as if kwargs was a Dict[str, Union[int, list[int]], but just specifying the value type is how static type checkers analyze it.

  1. If python.analysis.typeCheckingMode is set to strict, Pyright complains on almost every function that the types are partially unknown:
Type of "lookup_movie" is partially unknown
  Type of "lookup_movie" is "(term: str) -> list[dict[str, Unknown]]" Pylance[reportUnknownMemberType]

I think that this one might be a Pylance/Pyright issue though, as from what I can tell, JsonDataType/JsonObject/JsonArray shouldn't be statically analyzed to have anything be unknown. Felt like pointing it out as it did break some stuff for me.
After looking into it further, it's because there are generics (namely, list and dict) that aren't being specified. I just cloned the repo and set Pyright checking to strict and a bunch of errors about this popped up. I assume this happens with mypy --strict as well. For example, JsonDataType should have list["JsonDataType"] and dict[str, "JsonDataType"] as part of the union instead of the bare generics list and dict (also, do the TypeVars in the types file have to be bound or can they just be normal Unions?).

Steps To Reproduce

No response

Expected behaviour

Definitives: RescanMovie should be added to RadarrCommands. The type hint for **kwargs in RadarrAPI.post_command and SonarrAPI.post_command should be updated (and probably the other *arrs if they have the same, I currently only use Radarr and Sonarr).

Would be nice: I do think there is also merit to declaring each possible function signature with typing.overload as described in #119, as I currently have to throw in a assert isinstance(ret_value, list) or assert isinstance(ret_value, dict) every time I call a function that returns Union[JsonArray, JsonObject] to stop any type checkers (pylance, mypy) from complaining.
For example, calling BaseArrAPI.get_root_folder() with no arguments always yields a JsonArray, and always yields a JsonObject if you pass an id_. Currently it yields a Union[JsonArray, JsonObject] no matter what arguments you pass it.

The partially unknown type error is probably not a pyarr issue.
I'm not familiar enough with Python type hinting to know exactly how to fix these issues, but the result of Pylance/Pyright (and mypy) not complaining when set to strict modes would be the desired outcome.

Pyarr Version

5.2.0

Python Version

3.10.0

Example Code

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@wthueb wthueb added the type/bug Something isn't working label Jul 31, 2023
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

No branches or pull requests

1 participant