v923z / micropython-ulab

a numpy-like fast vector module for micropython, circuitpython, and their derivatives
https://micropython-ulab.readthedocs.io/en/latest
MIT License
392 stars 110 forks source link

[BUG] Some type annotations don't include scalars #662

Closed kbsriram closed 4 months ago

kbsriram commented 5 months ago

Describe the bug Ulab version: 6.5.1-2D-c

Type annotations on some functions don't appear to include scalars.

To Reproduce

For instance, this code:

from ulab import numpy as np

np.acos(0)

when used with the current type annotation extracted by circuitpython produces this error with mypy.

$ export MYPYPATH=${HOME}/circuitpython/circuitpython-stubs
$ mypy --disallow-untyped-defs type_test.py
type_test.py:3: error: Argument 1 to "acos" has incompatible type "int"; expected "Union[ndarray, List[float], Tuple[float], range]"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

Expected behavior The code accepts both scalars and _ArrayLike - so I was expecting type-checking to work.

Additional context Would one option be to add a TypeAlias that unions scalars with _ArrayLike, and use that for methods that accept or produce both scalars and arrays?

v923z commented 5 months ago

The issue concerns the documentation and not the code directly, right?

kbsriram commented 5 months ago

It's indeed just the type annotation in the documentation, not the implementation.

v923z commented 5 months ago

OK. Then it's not a bug.

v923z commented 5 months ago

I think circuitpython have a clean-up of the documentation on their milestone.

v923z commented 5 months ago

E.g., https://github.com/adafruit/circuitpython/issues/8715 mentions a similar issue. I wonder, whether we should collect all these. And it would be appreciated, if you could contribute in any way.