jfjlaros/arduino-simple-rpc

Type hinting using any vs typing.Any

gpantazis opened this issue · 3 comments

Describe the bug
This "bug" relates mostly to how type hints are handled. It is most problematic for static type checkers like mypy or pyright/pylance. By annotating variables or return values as having type any instead of typing.Any results in the type checker thinking the variable/return value should be of type "(__iterable: Iterable[object]) -> bool" i.e the type of the built-in Python function any

To Reproduce
Run static type checker on code using the simpleRPC library. For example:

value = rpc_interface.call_method("something") / 1000

Should produce a type checking error of
Operator "/" not supported for types "(__iterable: Iterable[object]) -> bool" and "Literal[1000]"
Notice that "(__iterable: Iterable[object]) -> bool" is the type hint for the built-in function any that takes in an iterable and returns a bool

Solution
To resolve change the signature of call_method from:
def call_method(self: object, name: str, *args: list) -> any:
to:
def call_method(self: object, name: str, *args: list) -> typing.Any:

I imagine it is a relatively easy fix for the rest of the variables/return values as well

Thank you for the easy to use library btw!

Thank you for this report and the clear explanation.

I just pushed a new version, does this solve your issue?

Just did a pip install of the library directly from git (python -m pip install git+https://github.com/jfjlaros/arduino-simple-rpc.git for any future readers) and all the typing issues seem to be resolved.

Thank you for the quick response on your end and apologies for the delay in getting back to you!

Thank you for the feedback. I will release a new version of the library.